Wednesday 15 June 2011

c# - Read XML file with several namespaces -



c# - Read XML file with several namespaces -

i have xml file several namespaces. cant value/ text of nodes.

<?xml version="1.0" encoding="utf-8"?> <!--xml file created microsoft dynamics c5--> <invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:invoice-2" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:commonaggregatecomponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:commonbasiccomponents-2" xmlns:udt="urn:un:unece:uncefact:data:specification:unqualifieddatatypesschemamodule:2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:commonextensioncomponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:qualifieddatatypes-2"> <cbc:ublversionid schemeagencyid="320" schemeagencyname="urn:oioubl:id:profileid-1.1">2.0</cbc:ublversionid> <cbc:customizationid>oioubl-2.02</cbc:customizationid> <cbc:profileid schemeid="urn:oioubl:id:profileid-1.2" schemeagencyid="320">procurement-bilsim-1.0</cbc:profileid> <cbc:id>88481</cbc:id> <cbc:issuedate>2012-05-21</cbc:issuedate> <cbc:invoicetypecode listid="urn:oioubl:codelist:invoicetypecode-1.1" listagencyid="320">380</cbc:invoicetypecode> <cbc:documentcurrencycode>dkk</cbc:documentcurrencycode> <cbc:accountingcost></cbc:accountingcost> <cac:orderreference> <cbc:id>zz</cbc:id> <cbc:salesorderid>36433</cbc:salesorderid> <cbc:issuedate>2012-05-21</cbc:issuedate> </cac:orderreference> </invoice>

i'm trying read of nodes cant. here example.

xmldocument doc = new xmldocument(); doc.load(@"c:\temp\88481.xml"); xmlnamespacemanager manager = new xmlnamespacemanager(doc.nametable); manager.addnamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:commonbasiccomponents-2"); manager.addnamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:commonaggregatecomponents-2"); manager.addnamespace("qdt", "urn:oasis:names:specification:ubl:schema:xsd:qualifieddatatypes-2"); manager.addnamespace("xsd", "http://www.w3.org/2001/xmlschema"); manager.addnamespace("udt", "urn:un:unece:uncefact:data:specification:unqualifieddatatypesschemamodule:2"); manager.addnamespace("ccts", "urn:un:unece:uncefact:documentation:2"); manager.addnamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:commonextensioncomponents-2"); manager.addnamespace("", "urn:oasis:names:specification:ubl:schema:xsd:invoice-2"); xmlnodelist list = doc.selectnodes("//invoice/cbc:id", manager);

but node list have no elements ?

you close first time.

like jon skeet mentioned, "invoice" root element don't need declare new namespace.

xmldocument doc = new xmldocument(); doc.load(@"c:\temp\88481.xml"); xmlnamespacemanager manager = new xmlnamespacemanager(doc.nametable); manager.addnamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:commonbasiccomponents-2"); manager.addnamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:commonaggregatecomponents-2"); manager.addnamespace("qdt", "urn:oasis:names:specification:ubl:schema:xsd:qualifieddatatypes-2"); manager.addnamespace("xsd", "http://www.w3.org/2001/xmlschema"); manager.addnamespace("udt", "urn:un:unece:uncefact:data:specification:unqualifieddatatypesschemamodule:2"); manager.addnamespace("ccts", "urn:un:unece:uncefact:documentation:2"); manager.addnamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:commonextensioncomponents-2"); //manager.addnamespace("", "urn:oasis:names:specification:ubl:schema:xsd:invoice-2"); xmlnodelist list = doc.selectnodes("//cbc:id", manager);

c# xml

No comments:

Post a Comment