python - Is it possible get all context nodes used to evalute xpath result? -
Is it possible to use all reference nodes to spin the xpath result? In the code below:
test_xml = "" " r> gt; & lt; b & gt; & lt; b / & gt; ; & lt; / a & gt; & lt; / R & gt; "" "test_root = lxml.etree.fromstring (Test_xml) node for res = test_root.xpath ("// following-sibling :: * [1] / b"): res: print test_root.getroottree (). Getpath (node)
The results are:
/ r / a [2] / b / r / x [x] / r / a [1] / a [3] / b
Is it possible that all reference nodes should be used in the xpath evaluation above: R / a [2 ] / R / a [2] / b
and for the second result:
/ r / a [2] / r / a [3 ] / B / r / a [3] / b
? When using the hair axis, I can get those nodes from working on
element_tree.getpath (elem)
, but do other axes about?
Tia, relation
I have reverse xpath for each step So that the received items can be evaluated for the result:
for res in node: j = node.xpath ('./ parent :: *') [0] k = j.xpath ( './ predecessor-sibling :: * [1]') [0] # You did not specify these but their evaluation in ancestors = k.xpath ('./cestor :: *') [node, j, k ] Was done for the ancestors: Print items. Gatorotry (). The gatepath prints \ n \ n '
gives me:
/ r / a [2] / b, / R / a [2] , / R / a [1], / r
/ r / a [3] / b, / r / a [3], / r / a [2] / r
/>
Comments
Post a Comment