Featured post
.net - How do I guarantee node order for an XPath 'OR' query -
i have snippet of xml looks like
<body> text.... <nodea>....</nodea> more text <someothernode> <nodea>.......</nodea> </someothernode> <nodeb>.......</nodeb> etc..... </body>
i'm selecting nodea , nodeb nodes inside <body>
using xpath query similar //nodea|//nodeb
as understand it, .net supports xpath 1.0 not guarantee node order.
how can guarantee selected nodes returned in document order in or query : that's say:
nodea, nodea, nodeb
as understand it, .net supports xpath 1.0 not guarantee node order
when xpath 1.0 expression selects nodes evaluated, selected nodes form node-set. a node-set set , this, among many other things, means unordered.
for practical purposes, though, there 1 main ordering chosen enumerate nodes of node set: document order. in practice, xpath 1.0 engines know (and in .net) return selected nodes in document order. in future unlikely change, because vendors try preserve backwards compatibility.
therefore, try using selectnodes()
or evaluate()
methods , verify nodes in results in document order.
do note: order of following cannot guaranteed , implementation-dependent:
attributes of same element.
nodes belonging different documents (a node-set containing nodes different documents can produced using xslt function
document()
, of no concern you).
- Get link
- X
- Other Apps
Comments
Post a Comment