Reputation: 309
I have this problem. I need to read xml and get All the values in the tag (there are many), my problem is that they all appear in 1 line like this:
111/222/333
but I need them like this
111/
222/
333
How would I do It?
My current code Is
XmlDocument xmlDocument2 = new XmlDocument { XmlResolver = null };
xmlDocument2.Load("http://fota-cloud-dn.ospserver.net/firmware/" + csc + "/" + model + "/version.test.xml");
XmlNodeList z = xmlDocument2.GetElementsByTagName("upgrade");
string k = z[0].InnerText;
File.WriteAllText("z.txt", k);
Example xml: http://fota-cloud-dn.ospserver.net/firmware/SEB/SM-A600FN/version.test.xml
<upgrade>
<value rcount="15" fwsize="190580485">A600FNXXU5CTA1/A600FNOXM5CTA1/A600FNXXU5CTA1</value>
<value rcount="1" fwsize="492203630">A600FNXXU2ARG5/A600FNOXM2ARF7/A600FNXXU2ARF7</value>
<value rcount="4" fwsize="524681746">A600FNXXU3BSE2/A600FNOXM3BSE2/A600FNXXU3BSD2</value>
....
</upgrade>
Everything from upgrade
to </upgrade>
Upvotes: 0
Views: 142
Reputation: 18153
You could do
var data = xmlDocument2.SelectNodes("/versioninfo/firmware/version/upgrade/value")
.Cast<XmlElement>()
.SelectMany(x=>x.InnerText.Split('/').Select(c=>$"{c}/"));
File.WriteAllLines(filePath,data);
Sample Output
A600FNXXU5CTA1/
A600FNOXM5CTA1/
A600FNXXU5CTA1/
A600FNXXU2ARG5/
A600FNOXM2ARF7/
A600FNXXU2ARF7/
A600FNXXU3BSE2/
A600FNOXM3BSE2/
A600FNXXU3BSD2/
A600FNXXU0ARCB/
A600FNOXM0ARCB/
A600FNXXU0ARCB/
.....
.....
.....
Upvotes: 1