我想取出XML文件里面所有的orders节点以及下面所有子节点的值。
XML文件如下<etlive xmlns="http://etlive.com/integration/xmlbean">
    <results>
        <info>
            <timeStamp>Fri Mar 02 10:03:03 PST 2012</timeStamp>
            <site>jessicasimpson</site>
            <environment>production</environment>
            <vmType/>
            <host/>
            <vmId>jessicasimpson-prod-iws1</vmId>
            <systemLocale>en</systemLocale>
            <driver>oracle.jdbc.driver.OracleDataSource</driver>
            <dbUrl>jdbc:oracle:thin:@10.100.3.60:1523:SAPRD7G1</dbUrl>
        </info>
        <result>
<output>
<orders>
<order pk="107101">
    <code>ML_107101</code>
    <dateCreated>2012-03-02T09:37:13.889-08:00</dateCreated>
    <dateModified>2012-03-02T09:37:13.924-08:00</dateModified>
    <siteCode>jessicasimpson</siteCode>
    <locale>en_US</locale>
    <customerCode>ML_180988</customerCode>
    <status>Ordered</status>
    <subTotal>88.20</subTotal>
    <taxTotal>0.00</taxTotal>
    <shippingTotal>22.00</shippingTotal>
    <shippingCostTotal>7.00</shippingCostTotal>
    <shippingMethodTotal>15.00</shippingMethodTotal>
    <shippingWeightTotal>0.00</shippingWeightTotal>
    <shippingLocationTotal>0.00</shippingLocationTotal>
    <giftWrapTotal>0.00</giftWrapTotal>
    <additionalAddressTotal>0.00</additionalAddressTotal>
    <additionalChargesTotal>0.00</additionalChargesTotal>
    <weightSurchargeTotal>0.00</weightSurchargeTotal>
    <total>110.20</total>
    <merchandiseTotal>98.00</merchandiseTotal>
    <deferred>false</deferred>
    <multipleAddresses>false</multipleAddresses>
    <sourceCodesAsString>WELCOME10*|*</sourceCodesAsString>
    <deleted>false</deleted>
    <dateOrdered>2012-03-02T09:37:13.888-08:00</dateOrdered>
    <billToInfo pk="107502">
        <code>ML_107502</code>
        <dateCreated>2012-03-02T09:37:13.888-08:00</dateCreated>
        <dateModified>2012-03-02T09:37:13.888-08:00</dateModified>
        <attributePages>
            <attributePage>
                <name>person</name>
                <attributes>
                    <firstName>Brandi</firstName>
                    <lastName>Pharr</lastName>
                </attributes>
            </attributePage>
            <attributePage>
                <name>address</name>
                <attributes>
                    <street1>293 Marion Place</street1>
                    <postOfficeBox>false</postOfficeBox>
                    <city>Merritt Island</city>
                    <state>FL</state>
                    <country>US</country>
                    <postalCode>32953</postalCode>
                </attributes>
            </attributePage>
        </attributePages>
        <phone1>3214463699</phone1>
        <email>[email protected]</email>
    </billToInfo>
    <shipments>
        <orderShipment pk="107101">
            <code>ML_107101</code>
            <dateCreated>2012-03-02T09:37:13.842-08:00</dateCreated>
            <shipToInfo pk="107501">
                <code>ML_107501</code>
                <dateCreated>2012-03-02T09:37:13.796-08:00</dateCreated>
                <dateModified>2012-03-02T09:37:13.796-08:00</dateModified>
                <attributePages>
                    <attributePage>
                        <name>person</name>
                        <attributes>
                            <firstName>Brandi</firstName>
                            <lastName>Pharr</lastName>
                        </attributes>
                    </attributePage>
                    <attributePage>
                        <name>address</name>
                        <attributes>
                            <street1>293 Marion Place</street1>
                            <postOfficeBox>false</postOfficeBox>
                            <city>Merritt Island</city>
                            <state>FL</state>
                            <country>US</country>
                            <postalCode>32953</postalCode>
                        </attributes>
                    </attributePage>
                </attributePages>
                <phone1>3214463699</phone1>
                <email>[email protected]</email>
            </shipToInfo>
            <status>Ordered</status>
            <shippingMethodCode>UPS1DY</shippingMethodCode>
            <shippingMethodName>UPS Next Day</shippingMethodName>
            <shippingMethodDescription>All orders placed by 10AM PST will arrive Next Business Day.</shippingMethodDescription>
            <subTotal>98.00</subTotal>
            <total>120.00</total>
            <shippingTotal>22.00</shippingTotal>
            <shippingCostTotal>7.00</shippingCostTotal>
            <shippingMethodTotal>15.00</shippingMethodTotal>
            <shippingWeightTotal>0.00</shippingWeightTotal>
            <taxTotal>0.00</taxTotal>
            <giftWrapTotal>0.00</giftWrapTotal>
            <additionalChargesTotal>0.00</additionalChargesTotal>
            <weightSurchargeTotal>0.00</weightSurchargeTotal>
            <merchandiseTotal>98.00</merchandiseTotal>
            <deleted>false</deleted>
            <items>
                <orderItem pk="107201">
                    <code>ML_107201</code>
                    <dateCreated>2012-03-02T09:37:13.842-08:00</dateCreated>
                    <categoryCode>C2-Sub Category 1</categoryCode>
                    <productCode>CATHI</productCode>
                    <productName>CATHI</productName>
                    <status>Ordered</status>
                    <regularPrice>98.00</regularPrice>
                    <sellPrice>98.00</sellPrice>
                    <subTotal>98.00</subTotal>
                    <qty>1</qty>
                    <ordinal>0</ordinal>
                    <sku>CATHIJV2811800</sku>
                    <skuPk>107437</skuPk>
                    <overWeight>false</overWeight>
                    <giftCertificate>false</giftCertificate>
                    <options>6,NATURAL COMBO</options>
                    <optionNames>6,Natural Combo</optionNames>
                    <freeGift>false</freeGift>
                    <kitPart>false</kitPart>
                </orderItem>
            </items>
        </orderShipment>
    </shipments>
    <discounts>
        <discount>
            <message>10% Off Discount has been applied</message>
            <amount>9.80</amount>
            <pricingName>10% OFF</pricingName>
            <sourceCodesAsString>WELCOME10*|*</sourceCodesAsString>
        </discount>
    </discounts>
</order>
</orders></output>
<summary>
    <total>3</total>
    <failed>0</failed>
</summary></result></results></etlive>

解决方案 »

  1.   

    自己看xmldocument帮助和xdocument帮助,或google相关资料
      

  2.   

    我写的代码XmlDocument xmlDoc = new XmlDocument();//实例化XmlDocument
                string xmlFile = HelperClass.GetFiles(new DirectoryInfo(System.IO.Directory.GetCurrentDirectory()), "*.xml");
                xmlDoc.Load(xmlFile);//加载xml文档
                XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("orders");//获取指定根节点下的所有节点
                foreach (XmlNode node in nodeList)
                {
                    Console.WriteLine(node.InnerXml.ToString());               
                }运行后什么都没有! XML文件肯定是加载上了!但是取出不来 orders节点及子节点的值
      

  3.   

    static void Main(string[] args)
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(@"E:\a.xml");
                XmlNamespaceManager xns = new XmlNamespaceManager(xml.NameTable);
                xns.AddNamespace("a","http://etlive.com/integration/xmlbean");
                XmlNode node = xml.SelectSingleNode("//a:orders", xns);
                ResponseText(node.ChildNodes);
                Console.ReadLine();
            }
            protected static void ResponseText(XmlNodeList node)
            {
                foreach (XmlNode n in node)
                {
                    if (n.HasChildNodes)
                        ResponseText(n.ChildNodes);
                    else
                        Console.WriteLine(n.InnerText);
                }
            }
    /*
    ML_107101
    2012-03-02T09:37:13.889-08:00
    2012-03-02T09:37:13.924-08:00
    jessicasimpson
    en_US
    ML_180988
    Ordered
    88.20
    0.00
    22.00
    7.00
    15.00
    0.00
    0.00
    0.00
    0.00
    0.00
    0.00
    110.20
    98.00
    false
    false
    WELCOME10*|*
    false
    2012-03-02T09:37:13.888-08:00
    ML_107502
    2012-03-02T09:37:13.888-08:00
    2012-03-02T09:37:13.888-08:00
    person
    Brandi
    Pharr
    address
    293 Marion Place
    false
    Merritt Island
    FL
    US
    32953
    3214463699
    [email protected]
    ML_107101
    2012-03-02T09:37:13.842-08:00
    ML_107501
    2012-03-02T09:37:13.796-08:00
    2012-03-02T09:37:13.796-08:00
    person
    Brandi
    Pharr
    address
    293 Marion Place
    false
    Merritt Island
    FL
    US
    32953
    3214463699
    [email protected]
    Ordered
    UPS1DY
    UPS Next Day
    All orders placed by 10AM PST will arrive Next Business Day.
    98.00
    120.00
    22.00
    7.00
    15.00
    0.00
    0.00
    0.00
    0.00
    0.00
    98.00
    false
    ML_107201
    2012-03-02T09:37:13.842-08:00
    C2-Sub Category 1
    CATHI
    CATHI
    Ordered
    98.00
    98.00
    98.00
    1
    0
    CATHIJV2811800
    107437
    false
    false
    6,NATURAL COMBO
    6,Natural Combo
    false
    false
    10% Off Discount has been applied
    9.80
    10% OFF
    WELCOME10*|**/
      

  4.   


    老哥请问一下,如果有多个一个orders下面有多个order我该怎么一个一个的取出,并且分别取出每个order里面的billToInfo节点之前数据 和 下级的数据? 之前的数据 和 下级的数据是分开的