Hi all, I think this is a pretty easy one.
Let's say I have this XML named "datafile.xml":
<bookstore>
<book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
![CDATA[The Autobiography of Benjamin Franklin]]>
</book>
<book genre="Literary" publicationdate="1995-12-01" ISBN="1-845269-25-5">
![CDATA["Gone with the Wind"]]>
</book>
<book genre="Business and Economics" publicationdate="2006-05-25" ISBN="1-452367-96-6">
![CDATA["Business Law Text and Cases"]]>
</book>
</bookstore>
I'm using XMLReader to parse it.
StringBuilder output = new StringBuilder();
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = new XmlXapResolver();
XmlReader reader = XmlReader.Create("datafile.xml");
reader.ReadToFollowing("book");
string title = reader.ReadElementContentAsString();
string book = reader.value;
output.Append(title);
reader.Close();
OutputTextBlock.Text = output.ToString();
My question is, how can I read the number of elements in the XML, in this case "book"? it should be 3. I've tried validating it using HasValue, but it does not work.
Thanks a lot!