开发者

Can't get XPath query to return the right nodeset

I've got an xml file that looks like this:

<Records>
<Record>
 <table>
  <Row>
   <col1>value1</col1>
  </Row>
 </table>
</Record>
<Record>
 <table>
  <Row>
   <col1>value2</col1>
  </Row>
 </table>
</Record><Record>
 <table>
  <Row>
   <col1>value3</col1>
  </Row>
 </table>
</Record>
</Records>

What I need is to select all the ROW nodes, across all records, so I'm using something like this:

rowiterator = Me.XMLDocument.CreateNavigator.Evaluate("//table/Row")

which is working, but it returns a NodeIterator that only contains the first Row node in the first record!?开发者_开发问答!

As far as I can tell, that's the proper syntax for an xpath expression of "return all Row nodes with a parent table name anywhere in the document".

I've got to be missing something simple, but I'm just not seeing it.

Any ideas?


You should use the XPathNavigator.Select method and loop through the iterator. Use the XPathNodeIterator.Current property to access the current XPathNavigator object in the loop.

Dim iter = xmldoc.CreateNavigator().Select("//table/Row")
While (iter.MoveNext())
    Console.WriteLine(iter.Current.Value)
End While
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜