parse xml

MRAB python at mrabarnett.plus.com
Fri Oct 15 14:46:52 EDT 2010


On 15/10/2010 18:49, kostia wrote:
> I have xml file:
> <?xml version="1.1" encoding="UTF-8"?>
> <root>
>          <n>50000</n>
> </root>
>
> I want to get the value of n (= 50000) inside my python program, I'm
> doing this:
>
> import xml.dom.minidom
> from xml.dom.minidom import Node
> doc = xml.dom.minidom.parseString("boolean_width.xml")
> n = doc.getElementsByTagName("root")[0].firstChild.nodeValue.strip()
> print n
>
> and it is failed. How to get the value? Please, help.

The 'parseString' method does what it says, it parses a string. You're
giving it the string "boolean_width.xml", so that's what it's parsing.

If you want to parse a file then use the 'parse' method.



More information about the Python-list mailing list