I'm using Python and lxml. My xml file:
<Example>
<Path>
<Some.Node>
// ...
</Some.Node>
<Some.Node>
<Known.Node KnownAttribute="123"/>
<Some.Stuff>
<Nothing.Important>Bla</Nothing.Important>
</Some.Stuff>
<Relevant.Node>
<Property>
<Name>Some</Name>
<Value>True</Value>
</Property>
<Property>
<Name>Known.Name</Name>
<Value>Desired Value</Value>
</Property>
<Property>
<Name>Some.Other</Name>
<Value>Yes</Value>
</Property>
// ...
</Relevant.Node>
// ...
</Some.Node>
<Some.Node>
// ...
</Some.Node>
</Path>
</Example>
There are multiple <Some.Node> nodes and I'm only interested in the one with KnownAttribute equal to 123. This part I got:
query = "//Known.Node[@KnownAttribute='%s']" % attribute_value
However, I need to get the value of <Relevant.Node>/<Property>/<Value> where <Name> has value Known.Name.
This was my best try but it didn't work:
root = etree.parse(xml_file).getroot()
query = "//Known.Node[@KnownAttribute='%s']/..//Property[Name='Known.Name']/Value" % attribute_value
result = root.xpath(query)
print(result[0].text)
It should print, of course, Desired Value but it just returns empty value/whitespace.
How can I get the value I need?