I have an xml file and I am trying to get a list of all of a particular node using c#.
A trimmed down version of my xml is:
<file>
<AnotherNode>
</AnotherNode>
<ROWS>
<row>
<code>Code1</code>
<R>1</R>
<G>2</G>
<B>3</B>
</row>
<row>
<code>Code2</code>
<R>1</R>
<G>2</G>
<B>3</B>
</row>
</ROWS>
</file>
There are multiple “row” nodes and I want a list of all the codes from within those nodes
The XPath I am using is:
/file/ROWS/row/code
with this code:
XmlDocument doc = new XmlDocument();
doc.Load(xml);
XmlNode root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes(xpath here);
foreach (XmlNode code in nodeList)
{
}
but I am returning no nodes.
What am I doing wrong?
Thanks.
Solution and suggestion if you are using at least .net 3.5.
Be sure to include “using System.Xml.XPath;”