Срба Срба - 5 months ago 26
Python Question

Why XmlNode.SelectNodes returns empty list when XPath validator returns correct result?

The code is in IronPython and here it is:

for systemNode in csResultXML.SelectNodes("Response/SubSystems/SubSystem"):

itemNodes = systemNode.SelectNodes('/SubSystem/Items/Item')


The value of systemNode in the single loop cycle is:

<SubSystem ID="0">
<Items>
<Item>
<Quantity>1</Quantity>
<TotalPrice>0.0</TotalPrice>
</Item>
<Item>
<Quantity>1</Quantity>
<TotalPrice>0.0</TotalPrice>
</Item>
</Items>
</SubSystem>


itemNodes is an empty list when the code finished.

Why?
XPath online validator returs results correctly.

Thank you for the time

Answer

You need to use systemNode.SelectNodes('Items/Item') as you want to select the Items child element of the context node (your systemNode variable) and not the Items child element of the document node /.

Comments