How to get parent of a node with some specific value in xml using lxml python -
i new xml, , have problem in parsing it. have following xml:
<bookstore> <book> <name>abc</name> <price>30</price> </book> <book> <name>learning xml</name> <price>56</price> </book> <book> <name>learning java</name> <price>340</price> </book> <book> <name>learning python</name> <price>560</price> </book> </bookstore>
i want name of book price 30. how using lml python
you can use following xpath select <name>
element of <book>
<price>
equals 30 :
//book[price=30]/name
python example :
from lxml import etree tree = etree.parse('path_to_your_xml.xml') result = tree.xpath('//book[price=30]/name')[0] print result.text #above printed abc
Comments
Post a Comment