-1

I have a XML file and I need to extract some numeric values. I would like to write a simple Python script, which open/reads the file and extracts these values. How can I do that?

thank you very much!!!

This is how the file looks like; I want to extract the values inside " " and save them in an array my_values[].

<?xml version="1.0" standalone="yes" ?>
...
...
    <value x="0.000000">
        ...
        ...
    </value>
    <value x="1.000000">
    ...
    ...
....
user3546924
  • 27
  • 2
  • 4

1 Answers1

0

Searching for xml parser, you can find Python sdlib one, or my favourite lxml

Install lxml first:

from lxml import etree

xmlstr = """
<?xml version="1.0" standalone="yes" ?>
<xml>
    <value x="0.000000"></value>
    <other_tag/>
    <value x="1.000000"/>
</xml>"""

doc = etree.fromstring(xmlstr.strip())
values = doc.xpath("//value/@x")
print values
Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98