Hi all,
I am trying to read an XML file and can't get the node "cbc:Name". I can get the other nodes I want but not the supplier node with name and address etc. The XML I try to read is (Part of it)
<?xml version="1.0" encoding="UTF-8"?><Invoice xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:udt="urn:un:unece:uncefact:data:draft:UnqualifiedDataTypesSchemaModule:2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><cbc:UBLVersionID>2.0</cbc:UBLVersionID><cbc:ID>16006955</cbc:ID><cbc:IssueDate>2016-02-08</cbc:IssueDate><cbc:Note>WSO:377813</cbc:Note><cbc:TaxPointDate>2016-02-08</cbc:TaxPointDate><cbc:AccountingCostCode></cbc:AccountingCostCode><cbc:AccountingCost></cbc:AccountingCost><cac:AccountingSupplierParty><cac:Party><cac:PartyName><cbc:Name>Complies BV</cbc:Name></cac:PartyName><cac:PostalAddress><cbc:StreetName>Handelsweg 30 -32</cbc:StreetName><cbc:CityName>Tynaarlo</cbc:CityName><cbc:PostalZone>9482 WE</cbc:PostalZone><cac:Country><cbc:IdentificationCode>NL</cbc:IdentificationCode></cac:Country></cac:PostalAddress>
While trying to get
cac:AccountingSupplierParty
can't get the next nodes until cbc:Name. My code is here
using (XmlReader lezer = XmlReader.Create("Complies.xml")) { string substr = ""; while (lezer.Read()) { switch (lezer.NodeType) { case XmlNodeType.Element: // Het knooppunt is een element. substr = lezer.Name; if (substr == "cac:AccountingSupplierParty") { if (lezer.HasAttributes) { for (int i = 0; i < lezer.AttributeCount; i++) { lezer.MoveToAttribute(i); Console.Write(" {0}={1}", lezer.Name, lezer.Value); switch (lezer.Name) { case "cbc:Name": leverancier = lezer.Value; break; } } } } break; case XmlNodeType.Text: //De tekst in elk element weergeven. switch (substr) case "cbc:Percent": string temp = lezer.Value; temp = temp.Replace('.', ','); percent = decimal.Parse(temp); break; case "cbc:Description": artikel = lezer.Value; break; // reading another 2 nodes
I need only the name of the supplier, the rest is correct.
Rinaldo
Full of ideas but don't know how. Coding for fun.