如何使用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)?
原文:
最满意答案
你能试一下吗
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 ...