Thursday, December 22, 2011

C# : Counting "rows" in an XML structutre

Working on a system that returns an XML structure as a string.

The structure looks like:

Table
Row
Info1/
Info2/
...
/Row
/Table

I needed to find out how many rows there were.

Mr. Google to the rescue and the solution is:
XmlDocument readTable = new XmlDocument();

readTable.LoadXml(stringXml);
int rowCount = readTable.SelectNodes("Table/Row").Count;
Refer XPath Examples for the syntax of more kinds of searches you can do.

Enjoy!

1 comment:

error 1310 said...

Hello,

Great information and I have not listened about this information about xml.