开发者

C# XPathNavigator returns string of all values instead of values

开发者 https://www.devze.com 2023-01-07 08:24 出处:网络
I have XML document which is something like <X><Y><Values><double>1.0<开发者_开发问答;/double><double>2.0</double></Values>...

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"


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号