0

I have the following XML:

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Header/>
    <env:Body>
        <DigSales xmlns="urn:nike:sale:DigitalSalesToSabrix" xmlns:ns2="http://xmlns.int.nike.com/WSFault" FileTime="2014-09-19T23:16:21Z">
            <Tran OrderType="STANDARD" OperatorID="" IsComplimentary="false" ConsumerID="1260046" Currency="USD" InvoiceNo="17779214" BillDate="2014-09-19" BillTime="2014-09-19T22:23:14Z" OrderDate="2014-09-18T20:50:01Z" TranDate="2014-09-19T22:23:14Z" OrderNo="O917950017" StoreNo="150" TranNo="17779214" IsTaxExempt="false">
                <Item isTaxExempt="false" IsTaxInvoiceStatus="true" TaxDate="2014-09-18T13:49:56" IsShipSend="true" Style="SX4801" Commodity_CD="531024" Desc="Nike Hyper Elite Crew Basketball Socks" ActValue="36.00" ID="00884498939512" InvSource="BRD" NormValue="36.00" Qty="2" Type="2001" isNotOnFile="false">
                    <Tax IsManualOverride="false" TaxAmt="3.15"/>
                    <ShipTo Country="US" GeoCode="8382" PostalCode="94102" State="CA" City="SFO" District="" Address2="" Address1="P.O. Box 15687"/>
                    <ShipFrom ShipFromNode="BRD" Country="US" GeoCode="7533" PostalCode="38118" State="TN" City="Memphis" Address2="" Address1="4775 TUGGLE RD DOOR 54"/>
                </Item>
                <Item isTaxExempt="false" IsTaxInvoiceStatus="true" TaxDate="2014-09-18T13:49:56" IsShipSend="false" Style="" Commodity_CD="7812" Desc="Shipping" ActValue="8.00" ID="00000000000100" NormValue="8.00" Qty="1" Type="2002" isNotOnFile="false">
                    <Tax IsManualOverride="false" TaxAmt="0.70"/>
                    <ShipTo Country="US" GeoCode="8382" PostalCode="94102" State="CA" City="SFO" District="" Address2="" Address1="P.O. Box 15687"/>
                    <ShipFrom ShipFromNode="150" Country="US" GeoCode="7533" PostalCode="38118" State="TN" City="Memphis" Address2="" Address1="4775 TUGGLE RD DOOR 54"/>
                </Item>
                <ContactInfo LastName="PO Box" FirstName="Test"/>
            </Tran>
        </DigSales>
    </env:Body>
</env:Envelope>

I cannot parse to "Tran". I have written the following for parsing:

var body = xdoc.Descendants(XNamespace.Get("http://schemas.xmlsoap.org/soap/envelope/") + "Body").Single();

var nmspc = XNamespace.Get("http://schemas.xmlsoap.org/soap/envelope/");

var tran = from trans in xdoc.Element(nmspc + "Body").Elements("DigSales")
           select trans.Elements("DigSales").Elements("Tran").ToList();

Please help.

2
  • You seem to be confusing "parsing" with something else. You already have xdoc, which is likely to be an object which contains all of the parsed data. What is it you are trying to do? and what about it isn't working for you? Commented Sep 25, 2014 at 20:40
  • I need the Tran data in a data table and Item data in another datatable with InvoiceNo as the foreign key which will be present in both tables. Commented Sep 25, 2014 at 20:43

1 Answer 1

1

This will get you an IEnumerable of the Tran elements:

var nmspc = XNamespace.Get(@"http://schemas.xmlsoap.org/soap/envelope/");
var ns2 = XNamespace.Get(@"urn:nike:sale:DigitalSalesToSabrix");

var trans = xdoc.Root.Elements(nmspc + "Body").Elements(ns2 + "DigSales").Elements(ns2 + "Tran");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.