Hi All
I am having trouble selecting a particular node within an XML document. I have given a sample of the XML below
<?xml version="1.0" encoding="ISO-8859-1"?>
<NETWORK>
<Objects>
<ObjectType>
<Dataset>gis</Dataset>
<Projection>CoordSys Earth Projection 8, 79, "mm", -2, 49, 0.9996012717, 400000000, -100000000</Projection>
<TypeName>distribution_point</TypeName>
<Object>
<Attributes>
<Attribute>
<AttribName>type</AttribName>
<AttribValue>I</AttribValue>
<AttribType>string</AttribType>
<AttribLength>4</AttribLength>
</Attribute>
</Attributes>
</Object>
</ObjectType>
</Objects>
</NETWORK>
I am trying to traverse to the <AttribName> Nodes with the following C# code
XPathDocument xpDoc = new XPathDocument(fName);
XPathNavigator xpNav = xpDoc.CreateNavigator();
// Compile a standard XPath expression
XPathExpression xpExpr;
//xpExpr = xpNav.Compile("/catalog/cd/price");
xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object");
XPathNodeIterator xpNodeIterator = xpNav.Select(xpExpr);
// Iterate on the NodeSet
try
{
while (xpNodeIterator.MoveNext())
{
XPathNavigator xpNav2 = xpNodeIterator.Current.Clone();
result += ("AttribLength: " + xpNav2.Value + "\n");
}
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
However, when I execute the code, nothing is returned. I am fairly sure my XPath query is wrong but have tried everything.
I have tried the same code on simple XML examples and it works fine, but not with this XML.
Can anyone help?
Many thanks in advance
Anfield