Something similar to PHP's SimpleXML in Python?
Is there a way in Python to handle XML files similar to the way PHP's SimpleXML extension does them?
Ideally I just want to be able to access certain xml datas from a list object.
Asked by: Emily137 | Posted: 05-10-2021
There is a long list of libraries associated with XML processing on the Python wiki. Note that a number of them are included in the standard library. Most of them will do what you are looking for:
to access certain xml datas from a list object
which is a bit vague, and perhaps some more concrete use-case might narrow down that list for you.Answered by: Caroline679 | Posted: 06-11-2021
You might want to try xml.etree.ElementTree It provides many easy ways to access read xml and to build new xml.
Or better yet use lxml.etree that provides even more convenient ways of accessing the nodes (such as xpath)Answered by: Rafael647 | Posted: 06-11-2021
You might be referring to something like this:
I haven't used it myself, but I was also looking for something like simplexml in PHP and this link showed up.Answered by: Justin695 | Posted: 06-11-2021
lxml.objectify does exactly what you want
Answered by: Ada568 | Posted: 06-11-2021
In : from lxml import objectify In : x = objectify.fromstring("""<response><version>1.2</version><amount>1.01</amount><currency>USD</currency></response>""") In : x.version Out: 1.2 In : x.amount Out: 1.01 In : x.currency Out: 'USD'