我想读取所有order_h
和order_d
属性数据。但在我的程序代码上只能显示 order_h 标签数据。下面是我的代码。谢谢
<document>
<order>
<order_h owner="ABC" order_no="96431"/>
<order_d owner="ABC" order_no="96431" item_no="0153-8196-010">
<size assoc_id="1274847" size_id="B0153_0150XSXXLNIVINT_VAEC000076_BK"/>
</order_d>
<order_d owner="ABC" order_no="96431" item_no="0153-8196-020">
<size assoc_id="1274847" size_id="B0153_0150XSXXLNIVINT_VAEC000076_BK"/>
</order_d>
<order_h/>
</order>
<order>
<order_h owner="ABC" order_no="96432">
<order_d owner="ABC" order_no="96431" item_no="0153-8196-030">
<size assoc_id="1274847" size_id="B0153_0150XSXXLNIVINT_VAEC000076_BK"/>
</order_d>
<order_d owner="ABC" order_no="96431" item_no="0153-8196-040">
<size assoc_id="1274847" size_id="B0153_0150XSXXLNIVINT_VAEC000076_BK"/>
</order_d>
<order_h/>
</order>
</document>
XmlDocument doc = new XmlDocument();
doc.Load(@"File.xml");
XmlNode OrderListNode =
doc.SelectSingleNode("/document");
XmlNodeList OrderNodeList =
OrderListNode.SelectNodes("order/order_h");
foreach (XmlNode node in OrderNodeList)
{
Console.WriteLine(node.Attributes.GetNamedItem("owner").Value);
Console.WriteLine(node.Attributes.GetNamedItem("order_no").Value);
Console.WriteLine(node.Attributes.GetNamedItem("profoma_po").Value);
XmlNodeList OrderdNodeList = OrderListNode.SelectNodes("order_h/order_d");
foreach (XmlNode orderd in OrderdNodeList)
{
Console.WriteLine("D " + orderd.Attributes.GetNamedItem("owner").Value);
Console.WriteLine("D " + orderd.Attributes.GetNamedItem("order_no").Value);
Console.WriteLine("D " + orderd.Attributes.GetNamedItem("item_no").Value);
}
Console.WriteLine("*****************new Line*******************");
}