I need to file from
<?xml version="1.0" encoding="UTF-8"?> <messages> <message> <title>Заголовок</title> <text>Текст сообщения</text> </message> </messages>
it happened
object.message[0].title
I can not find a ready-made solution.I would be grateful if you tell me.
python-simplexml
OverviewIf I started working in Python Coming from PHP I had SimpleXML that worked perfectly fine for 99% of the XML parsing I had to do. Wrapping around the ElementTree.Usage from simplexml import parse xml = parse("person.xml") print xml.name.first print xml.name.last print xml.name["origin"]
Overview
If I started working in Python Coming from PHP I had SimpleXML that worked perfectly fine for 99% of the XML parsing I had to do. Wrapping around the ElementTree.
Usage
from simplexml import parse xml = parse("person.xml") print xml.name.first print xml.name.last print xml.name["origin"]
from lxml import etree tree = etree.parse('example.xml') raws = tree.xpath('//message') for raw in raws: print raw.xpath('title')[0].text
if there is only one item
raws = tree.xpath('//message/title') print raws[0].text
Source: https://ru.stackoverflow.com/questions/121752/More articles:How to pass a parameter?Navigation menu item highlightsQuestion on writing * .bat file.Using DBM files in PerlCreating games for AndroidHow to prevent submit?The first line in the lists disappearsHow to customize the design of a standard HTML5 audio player.Website using Google App Engine [closed]Fast key update inside heap in Dijkstra algorithmAll Articles