By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

C# and XPath problem

P: 2
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"?>
<Projection>CoordSys Earth Projection 8, 79, "mm", -2, 49, 0.9996012717, 400000000, -100000000</Projection>

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
while (xpNodeIterator.MoveNext())
XPathNavigator xpNav2 = xpNodeIterator.Current.Clone();
result += ("AttribLength: " + xpNav2.Value + "\n");
catch (Exception ex)

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
Mar 23 '06 #1
Share this Question
Share on Google+
1 Reply

P: 2
Sorry, I forgot to amend the expression I am using. It is not

xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object"); as stated but

xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object/Attributes/Attribute/AttribName");
Mar 23 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.