How do I get the value out of a DOM Element
stefan.behnel-n05pAM at web.de
Thu Sep 27 09:28:14 CEST 2007
> I have been able to get xml.dom.minidom.parse('somefile.xml') and then
> dom.getElementsByTagName('LLobjectID') to work to the point where I
> get something like: [<DOM Element: LLobjectID at 0x13cba08>] which I
> can get down to <DOM Element: LLobjectID at 0x13cba08> but then I
> can't find any way to just get the value out from the thing!
> .toxml() returns something like: u'<LLobjectID><![CDATA]></
> How do I just get the 1871203 out of the DOM Element?
It contains a CDATA node which in turn contains a Text node (AFAIR), so you
have to walk through the children to get what you want.
Alternatively, try an XML API that makes it easy to handle XML, like
ElementTree (part of the stdlin in Python 2.5) or lxml, both of which have
compatible APIs. The code would look like this:
tree = etree.parse("some_file.xml")
id = tree.find("//LLobjectID")
More information about the Python-list