Counting elements and reading attributes with .net2.0 ?
Posted
by
Prix
on Stack Overflow
See other posts from Stack Overflow
or by Prix
Published on 2011-03-02T04:51:19Z
Indexed on
2011/03/02
23:25 UTC
Read the original article
Hit count: 311
I have an application that is on .net 2.0 and I am having some difficult with it as I am more use to linq.
The xml file look like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<updates>
<files>
<file url="files/filename.ext" checksum="06B9EEA618EEFF53D0E9B97C33C4D3DE3492E086" folder="bin" system="0" size="40448" />
<file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" />
<file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" />
</files>
</updates>
The file is downloaded and readed on the fly:
XmlDocument readXML = new XmlDocument();
readXML.LoadXml(xmlData);
Initially i was thinking it would go with something like this:
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("//files");
foreach (XmlNode node in nodes)
{
... im reading it ...
}
But before reading them I need to know how many they are to use on my progress bar and I am also clueless on how to grab the attribute of the file element in this case.
- How could I count how many "file" ELEMENTS I have (count them before entering the foreach ofc) and read their attributes ?
I need the count because it will be used to update the progress bar.
Overall it is not reading my xml very well.
© Stack Overflow or respective owner