首页 \ 问答 \ 如何使用Linq轻松解析XML - 需要一些示例代码[关闭](How to use Linq to parse through XML easly - Need some sample code [closed])

如何使用Linq轻松解析XML - 需要一些示例代码[关闭](How to use Linq to parse through XML easly - Need some sample code [closed])

我在我的SQL Server中使用XML Auto来查询数据。 我想知道如何最好地解析它提供的数据。

我的最终目标是提供带有值的项目列表,但我不知道有多少列或列的名称将至少在运行时从SQL中提取数据。

这是一个示例XML

  <animals>
    <animal name="Pig">
      <meat>
        <name>Prosciutto</name>
      </meat>
      <meat>
        <name>Speck</name>
      </meat>
    </animal>
    <animal name="Cow">
      <meat>
        <name>Clod</name>
      </meat>
      <meat>
        <name>Brisket</name>
      </meat>
      <meat>
        <name>Tri-tip</name>
      </meat>
    </animal>
    <animal name="Chicken">
      <meat>
        <name>Drumstick</name>
      </meat>
    </animal>
  </animals>

如何在列表中显示,并执行Linq2SQL(或Linq2XML)?


I am using XML Auto in my SQL Server to query data out. I want to know how best to parse through the data that it provides.

My end goal is to provide a list of items with their values, but I don't know how many columns or what the names of the columns will be until at least the data is pulled form SQL at runtime.

Here is a sample XML

  <animals>
    <animal name="Pig">
      <meat>
        <name>Prosciutto</name>
      </meat>
      <meat>
        <name>Speck</name>
      </meat>
    </animal>
    <animal name="Cow">
      <meat>
        <name>Clod</name>
      </meat>
      <meat>
        <name>Brisket</name>
      </meat>
      <meat>
        <name>Tri-tip</name>
      </meat>
    </animal>
    <animal name="Chicken">
      <meat>
        <name>Drumstick</name>
      </meat>
    </animal>
  </animals>

How can I show this in a list, and perform Linq2SQL (or Linq2XML)?


原文:
更新时间:2022-11-08 16:11

最满意答案

你能试一下吗

getActivity().startActivityForResult(intent, 1);

或者覆盖它自己的片段中的onActivityResult

我有反过来的问题我试图在我的片段中使用onActivityResult但有时它转到父活动所以我最终使用第一行并在父行为中处理它


can you try

getActivity().startActivityForResult(intent, 1);

or override onActivityResult in the fragment it self

I had the problem in reverse I was trying to use onActivityResult inside my fragment but sometimes it went to the parent activity so I ended up using the first line and handling it in the parent actvity

相关问答

更多
  • 此行为是仅与Fragment连接的实现细节。 从片段调用startActivityForResult() ,活动会记住稍后通知它。 在纯Android Activity此通知在dispatchActivityResult()内完成,因此在调用活动本身的onActivityResult()之前完成。 所以你只会收到一次结果。 在支持FragmentActivity您可以找到onActivityResult()的实现将结果传递给SupportFragment 。 为了找到这个片段, requestCode的高1 ...
  • 首先调用onActivityResult()然后onResume() 。 文件报价: protected void onActivityResult(int requestCode,int resultCode,Intent data) 自:API级别1当您启动的活动退出时调用,为您启动它的requestCode,返回的resultCode以及其中的任何其他数据。 如果活动显式返回,没有返回任何结果或在其操作期间崩溃,则resultCode将为RESULT_CANCELED。 当您的活动重新启动时,您将在o ...
  • 托管活动会覆盖onActivityResult ,但是没有调用super.onActivityResult来处理未处理的结果代码。 显然,尽管片段是启动startActivityForResult调用的片段,但活动在处理结果时获得了第一个镜头。 当您考虑片段的模块性时,这是有道理的。 一旦我对所有未处理的结果实施了super.onActivityResult ,该片段就处理了结果。 还从@siqing回答: 要得到你的片段中的结果,请确保你调用startActivityForResult(intent,11 ...
  • resultCode==2保留给BRAINTREE_RESULT_DEVELOPER_ERROR : 由于可解析的错误(身份验证,授权,需要SDK升级),付款方法流程暂停。 错误的原因将在以后的版本中返回。 您可能需要仔细检查SDK是否正确设置。 The resultCode==2 is reserved for BRAINTREE_RESULT_DEVELOPER_ERROR: The payment method flow halted due to a resolvable error (authen ...
  • 要接收结果,您应该使用startActivityForResult而不是startActivity To receive a result you should use startActivityForResult instead of startActivity
  • 我在MainActivity上调用了onActivityResult,并且它没有调用.so删除了switch case。现在它正在工作 switch (requestCode) { case ZBAR_SCANNER_REQUEST: case ZBAR_QR_SCANNER_REQUEST: I called onActivityResult on MainActivity and with this its not calling .so removed ...
  • 通常, onDestroy()在活动完成或从Backstack中删除时被调用。 我希望你在调用startActivityForResult(..)之前或之后不要在A中调用finish( ) 。 您可以通过按后退按钮从B(联系人选择器)返回吗? In general, onDestroy() gets called when an activity is finished or removed from the backstack. I hope you are not calling finish() in ...
  • @Override protected void onPause() { Log.v(LOG_TAG, "onPause()"); Intent data = new Intent(); data.putExtra(MainActivity.EXTRA_SEARCH, searchStr); if (getParent() == null) { setResult(Activity.RESULT_OK, data); } else { getP ...
  • 在SupportFragment中,您应该使用 public override void OnActivityResult(int requestCode, int resultCode, Intent data){ base.OnActivityResult (requestCode, resultCode, data); 代替 public override void OnActivityResult(int requestCode, Result resultCode, Intent dat ...
  • 你能试一下吗 getActivity().startActivityForResult(intent, 1); 或者覆盖它自己的片段中的onActivityResult 我有反过来的问题我试图在我的片段中使用onActivityResult但有时它转到父活动所以我最终使用第一行并在父行为中处理它 can you try getActivity().startActivityForResult(intent, 1); or override onActivityResult in the fragment ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。