1

I have XML document which is something like

<X><Y><Values><double>1.0</double><double>2.0</double></Values>...

I am trying to get those values:

toXpath.MoveToRoot(); // the X node name could be different
toXpath.MoveToFirstChild(); // this should be Y

string q = "Y/Values";
foreach (XPathNavigator x in toXpath.Select(q))

In x.Value I get something like "1.02.0"

4
  • It is indeed returning the values, but it's putting both values into x. Haven't used xpath in C# so I'm not sure what you need to do. Commented Jul 14, 2010 at 16:19
  • Please provide more information Commented Jul 14, 2010 at 18:31
  • I bet the same thing happens with a VB.NET program, which would make this the .NET XPathNavigator, not the C# XPathNavigator. Commented Jul 14, 2010 at 22:39
  • john i know everything you can say in advance. dont bother Commented Jul 15, 2010 at 0:07

1 Answer 1

1
Y/Values

selects a single element named Values and child of the element Y that is a child of the top element X.

string q = "Y/Values";       
foreach (XPathNavigator x in toXpath.Select(q))

Because the XPath expression selects just a single node, you don't need a foreach...

In x.Value I get something like "1.02.0"

This is exactly what you should get. The value of a node is the concatenation of all of its text-node descendents.

Most probably you want:

Y/Values/double
Sign up to request clarification or add additional context in comments.

2 Comments

"Because the XPath expression selects just a single node, you don't need a foreach..." - how do I iterate through all children of a selected node?
@Bobb: You append to the expression that selects this node /* and this will select all element-children of the node. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.