I have many xml-files which I need to parse. The xml-files are loaded from elsewhere. I can examine these files to get the paths I need to extract my desired data. The paths aren't the same. So I added the paths in an ini-file for each xml-file. This works fine for 5 of 6 files.
WebClient client = new WebClient();
data = client.DownloadData("ftp://some.site/my.xml");
MemoryStream stream = new MemoryStream(data);
XmlDocument xml_doc = new XmlDocument();
xml_doc.Load(stream);
var prod_ids = xml_doc.DocumentElement.SelectNodes("/Catalog/Products/Product/Product_Id/text()");
foreach (XmlNode node in prod_ids) {
[...]
}
In the last file I need to get 2 information from one subtree at once, because I have to combine them in one string, therefore reading all nodes seperatly doesn't work. See Example-XML:
<Catalog>
<Created><![CDATA[2020-11-16T00:22:11+01:00]]></Created>
<Products>
<Product>
<Product_Id><![CDATA[ABC]]></Product_Id>
<Color_Code><![CDATA[123]]></Color_Code>
<Size><![CDATA[]]></Size>
<Length>210</Length>
<Width>0</Width>
</Product>
<Product>
<Product_Id><![CDATA[ABC]]></Product_Id>
<Color_Code><![CDATA[456]]></Color_Code>
<Size><![CDATA[]]></Size>
<Length>44</Length>
<Width>55</Width>
</Product>
<Product>
<Product_Id><![CDATA[XYZ]]></Product_Id>
<Color_Code><![CDATA[123]]></Color_Code>
<Size><![CDATA[]]></Size>
<Length>150</Length>
<Width>11</Width>
</Product>
</Products>
</Catalog>
I'm lookig for some code which parses each subtree (/Catalog/Products/Product) in which I can read the innerText from Product_Id and Color_Code to combine them to one string. Any ideas?