Wednesday, 7 January 2015

Selecting nodes in between comments with xpath from xmldocument



I'm trying to get nodes in between comments.


example:



<Name>
<First>a</First>
<Last>b</Last>
</Name>
<!-- family names -->
<Name>
<First>c</First>
<Last>d</Last>
</Name>
<Name>
<First>e</First>
<Last>f</Last>
</Name>
<Name>
<First>g</First>
<Last>h</Last>
</Name>
<!-- family ends -->
<!-- other names -->
<Name>
<First>i</First>
<Last>j</Last>
</Name>
<Name>
<First>k</First>
<Last>l</Last>
</Name>
<!-- other ends -->


I'd like to be able to select the nodes in between the comment family names and family ends. Tried several ways with xpath, but I cant get further then selecting all comment nodes. When I want to select comment nodes containing value x, I do not get any result. So I'm not sure how to continue. for example:



var x = xml.SelectSingleNode("//comment()[contains('family names')]");


Thanks in advance.


No comments:

Post a Comment