如何查询嵌套节点? [英] How Do I Query For Nested Nodes?
本文介绍了如何查询嵌套节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要完成两件事,但找不到答案.
首先,我需要获得订单的摘要:
_orderId和_extPrice的总数
其次,我需要获取订单的详细信息:
_orderId _shipQty _itemId _itemDesc _extPrice
VB.NET中的示例将不胜感激.
我在下面提供了XML文件的示例.
I need to accomplish two things and have not been able find the answers.
First I need to get a summary of the order:
_orderId and the total for _extPrice
Secondly I need to get the details of the order:
_orderId _shipQty _itemId _itemDesc _extPrice
Examples in VB.NET would be much appreciated.
I have include a sample of the XML file below.
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <MB_ORDERS>
- <order>
<_orderId>00036642</_orderId>
<_orderDate>2011-11-02</_orderDate>
<_custPO>yepAnotherOne</_custPO>
<_salesRep>MEB</_salesRep>
<_custId>AN555</_custId>
<_custName>Joe Blow Customer</_custName>
<_billAdd1>PO BOX 123</_billAdd1>
<_billAdd2 />
<_billAdd3 />
<_billCity>Lonview</_billCity>
<_billState>AL</_billState>
<_billZip>36420</_billZip>
<_billCo>US</_billCo>
<_shipAdd1>850 Over WEST</_shipAdd1>
<_shipAdd2 />
<_shipAdd3 />
<_shipCity>Longview</_shipCity>
<_shipState>AL</_shipState>
<_shipZip>36420</_shipZip>
<_shipCountry />
<_shipContact>Fred The Guy</_shipContact>
<_contactPhone>(334)555-3136</_contactPhone>
<_emailOrderAck />
<_orderShipDate />
<_orderCarrier />
<_carrierProNo />
<_carrierQuote />
<_orderETA />
<_emailOrderShip />
- <ITEMS>
- <_lineItem>
<_shipQty>1</_shipQty>
<_itemId>00-00-055</_itemId>
<_itemDesc>TARP - 50x50 Blue</_itemDesc>
<_extPrice>66.00</_extPrice>
</_lineItem>
</ITEMS>
<SPC_INST />
</order>
- <order>
<_orderId>00036643</_orderId>
<_orderDate>2011-11-04</_orderDate>
<_custPO>yepAnother_1</_custPO>
<_salesRep>MEB</_salesRep>
<_custId>CA1258</_custId>
<_custName>OverCover</_custName>
<_billAdd1>1240 Main AVE.</_billAdd1>
<_billAdd2 />
<_billAdd3 />
<_billCity>Longview</_billCity>
<_billState>MA</_billState>
<_billZip>92879-2027</_billZip>
<_billCo>US</_billCo>
<_shipAdd1>1240 Main AVE.</_shipAdd1>
<_shipAdd2 />
<_shipAdd3 />
<_shipCity>Longview</_shipCity>
<_shipState>MA</_shipState>
<_shipZip>92879</_shipZip>
<_shipCountry />
<_shipContact />
<_contactPhone />
<_emailOrderAck />
<_orderShipDate />
<_orderCarrier />
<_carrierProNo />
<_carrierQuote />
<_orderETA />
<_emailOrderShip />
- <ITEMS>
- <_lineItem>
<_shipQty>33</_shipQty>
<_itemId>00-00-006</_itemId>
<_itemDesc>CONNECTORS - Small</_itemDesc>
<_extPrice>125.00</_extPrice>
</_lineItem>
- <_lineItem>
<_shipQty>432</_shipQty>
<_itemId>04-71-055</_itemId>
<_itemDesc>Strap Kit</_itemDesc>
<_extPrice>1814.00</_extPrice>
</_lineItem>
- <_lineItem>
<_shipQty>1</_shipQty>
<_itemId>SPC_INST</_itemId>
<_itemDesc>SPECIAL INSTRUCTIONS</_itemDesc>
<_extPrice>0.00</_extPrice>
</_lineItem>
</ITEMS>
- <SPC_INST>
<_spcInst>this is a spc inst test to see if</_spcInst>
<_spcInst>everything is working in regards to</_spcInst>
<_spcInst>the XML file being generated</_spcInst>
</SPC_INST>
</order>
</MB_ORDERS>
推荐答案
使用LINQ to XML手册的以下部分: ^ ].
如果这还不够,请阅读整本手册,并 http://msdn.microsoft.com/zh-我们/library/bb387098.aspx [ ^ ]并找出您需要的所有内容.
这是一个相当简单的话题. C#和VB.NET提供了很好的代码示例集.
—SA
Use this section of the LINQ to XML manual: http://msdn.microsoft.com/en-us/library/bb943906.aspx[^].
If this is not enough, get to the whole manual and http://msdn.microsoft.com/en-us/library/bb387098.aspx[^] and find out all you need.
This is a fairly simple topic. The good set of code samples is provided in C# and VB.NET.
—SA
这篇关于如何查询嵌套节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文