Reading XML Files with Name Spaces

Hi everyone, I want to read a xml-File and copy out some values of it.
I finished the tutorial with reading xml-Files. I also installed the XML-Package for the xml commands (like Deserialize).
So i simply use the command “deserialize xml” to read the xml file. After that i want to “Write Line” the value of an Element, like this <TaxNumber>0105560161234</TaxNumber>
But i don’t get it. I think the problem is the http-adress in the head of the file. So this are namespaces?
I then tried this code for “Write Line”:

xmldoc.Elements.Descendants("CustomsExportDeclaration").Descendants("DocumentControl").Descendants("Exporter").Descendants("TaxNumber").Value

And this are the first lines of my file:

<?xml version="1.0" encoding="UTF-8"?>
<CustomsExportDeclaration xmlns="http://ebxml.customs.go.th/XMLSchema/CustomsExportDeclaration_4_00">
<DocumentControl>
<ID>0000</ID>
<ReferenceNumber>DLSC601390302</ReferenceNumber>
<DocumentType>1</DocumentType>
<Exporter>
<TaxNumber>0105560161234</TaxNumber>

Sorry for my poor english! :slight_smile:
And thank you very much for your help!
Greetz,

Kosch

Hey @kosch

After Deserialize your xml just use below code to get TaxNumber.

XmlDocData.Descendants().Where(function(n) n.Name.LocalName = "TaxNumber").FirstOrDefault().Value

Regards…!!
Aksh

2 Likes

Hey @aksh1yadav,
thanks for your quick response! It works now :wink:
But my next problem is that there a two TaxNumbers. And now i need the second one. How do I this?
Is there a documentation of this NameSpaces-Functions?

<?xml version="1.0" encoding="UTF-8"?>
<CustomsExportDeclaration xmlns="http://ebxml.customs.go.th/XMLSchema/CustomsExportDeclaration_4_00">
<DocumentControl> <ID>0000</ID> <ReferenceNumber>DLSC601390302</ReferenceNumber> <DocumentType>1</DocumentType>

<Exporter>
	<TaxNumber>0105560161234</TaxNumber>
	<Branch>000000</Branch>
	<ThaiName><![CDATA[]]></ThaiName>
	<EnglishName><![CDATA[AAA RBRICKER LIMITED]]></EnglishName>
	<StreetAndNumber><![CDATA[23/42 65]]></StreetAndNumber>
	<District><![CDATA]]></District>
	<SubProvince><![CDATA[]]></SubProvince>
	<Province><![CDATA[]]></Province>
	<Postcode>11111</Postcode>
</Exporter>
<Agent>
			<TaxNumber>0105533020000</TaxNumber>     *//This TaxNumber
			<Branch>0000</Branch>
			
		</Agent>

Thanks a lot again!
Greetz,
Kosch

Hey @kosch

Try This:-

XmlDocData.Descendants().Where(function(n) n.Name.LocalName = “TaxNumber”).Skip(1).Value

Regards…!!
Aksh

2 Likes

Hey @aksh1yadav,

thanks so much, now it works and I get it ^^
But in some cases i have to Skip 6 times or more. And i get dynamic data, so maybe i have to skip 5 times. Can i access directly the value i need?
Thanks a lot.

Have a nice day!
Greetz,
Kosch

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.