I am trying to read the content of an xml file that contains an electronic invoice. For this I use namespace but I have not been able to extract the data found in the cac:AdditionalItemProperty element and specifically the cbc:Name02</cbc:Name>cbc:Value2023171843</cbc:Value> The code that I do is the following and additionally part of the xml. thanks for your help
File XML
<AttachedDocument xmlns="urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:data:specification:CoreComponentTypeSchemaModule:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#">
<ext:UBLExtensions>
...
</ext:UBLExtensions>
<cbc:UBLVersionID>UBL 2.1</cbc:UBLVersionID>
<cbc:CustomizationID>Doctos</cbc:CustomizationID>
<cbc:ID>DT41647</cbc:ID>
<cbc:IssueDate>2023-03-17</cbc:IssueDate>
<cbc:ParentDocumentID>DT41647</cbc:ParentDocumentID>
<cac:SenderParty>
...
</cac:SenderParty>
<cac:ReceiverParty>
...
</cac:ReceiverParty>
<cac:Attachment>
<cac:ExternalReference>
<cbc:MimeCode>text/xml</cbc:MimeCode>
<cbc:EncodingCode>UTF-8</cbc:EncodingCode>
<cbc:Description>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" standalone="no"?><Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sts="xxxx" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:oth="http://example.org/oth" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"><ext:UBLExtensions><ext:UBLExtension><ext:ExtensionContent>
<sts:xxxExtensions><sts:InvoiceControl><sts:InvoiceAuthorization>99999999</sts:InvoiceAuthorization><sts:AuthorizationPeriod><cbc:StartDate>2023-02-23</cbc:StartDate><cbc:EndDate>2024-02-23</cbc:EndDate></sts:AuthorizationPeriod><cac:AdditionalItemProperty><cbc:Name>01</cbc:Name><cbc:Value>105584152</cbc:Value></cac:AdditionalItemProperty><cac:AdditionalItemProperty><cbc:Name>02</cbc:Name><cbc:Value>2023171843</cbc:Value></cac:AdditionalItemProperty><cac:AdditionalItemProperty><cbc:Name>03</cbc:Name><cbc:Value>184000</cbc:Value><cbc:ValueQuantity unitCode="KG">1280</cbc:ValueQuantity></cac:AdditionalItemProperty></cac:Item><cac:Price><cbc:PriceAmount currencyID="PP">184000.00</cbc:PriceAmount><cbc:BaseQuantity unitCode="94">1.00</cbc:BaseQuantity></cac:Price></cac:InvoiceLine></Invoice> ]]>
</cbc:Description>
</cac:ExternalReference>
</cac:Attachment>
<cac:ParentDocumentLineReference>
</cac:ParentDocumentLineReference>
</AttachedDocument>
'code VbNet
m_xmld.Load(fileName)
Dim manager As XmlNamespaceManager = New XmlNamespaceManager(m_xmld.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")
Dim list As XmlNodeList = m_xmld.SelectNodes("//cac:Attachment//cac:ExternalReference//cbc:Description", manager) 'da resultado 2
'Dim nodeComprobante As XmlNode = m_xmld.SelectSingleNode("//cac:AdditionalItemProperty", manager)
Dim nodeComprobante As XmlNode
For Each Book As XmlNode In list
nodeComprobante = m_xmld.SelectSingleNode("//cac:AdditionalItemProperty", manager)
'TotalXML += Book.SelectSingleNode("//cac:AdditionalItemProperty", manager).InnerXml 'error
'Dim mCodigo As Object = New Book.Attributes.GetNamedItem("Name").Value 'error
Next
MessageBox.Show("Tota: " & TotalXML, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
You have a second XML file inside a CDATA section. You'll need to parse that separately. Something like the code below. I can't test it because the XML you have included seems incomplete:
Dim m_xmld = New XmlDocument
Dim manager As XmlNamespaceManager = New XmlNamespaceManager(m_xmld.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("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2")
m_xmld.Load(fileName)
Dim nodeDescription As XmlNode = m_xmld.SelectSingleNode("//cbc:Description", manager)
Dim childDoc = New XmlDocument
childDoc.LoadXml(nodeDescription.FirstChild.InnerText.Trim) '<< parse the CDATA section
Dim additional = childDoc.SelectSingleNode("//cac:AdditionalItemProperty[0]")
MessageBox.Show(additional.InnerText, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)