-2

order_hすべてのorder_d属性データを読み取りたい。しかし、私のプログラム コードでは、order_h タグ data.below を表示できます。ありがとう

<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*******************");

        }
4

1 に答える 1

0

SelectNodes別のオブジェクトのorder_dノードを呼び出す必要があります。order_d現在の に従属するノードが必要nodeな場合は、 を呼び出す必要がありSelectNodesますnode

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 = node.SelectNodes("/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*******************");
}
于 2012-12-18T15:02:47.997 に答える