Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: xml.dom.minidom empty nodeValue nonempty toxml() value

I have a line that gets the nodeValue of a Node:

parent.getElementsByTagName("Url")[0].nodeValue

that returns nothing:

<br/>

When I do:

parent.getElementsByTagName("Url")[0].toxml()

it returns:

< Url>www.something.com< /Url>

I am not sure what is going on here. Another data point: when I do nodeName instead of nodeValue it returns, as expected, Url.

Any thoughts?

like image 974
tom Avatar asked Jan 24 '10 22:01

tom


People also ask

What is XML DOM. minidom?

xml. dom. minidom is a minimal implementation of the Document Object Model interface, with an API similar to that in other languages.

Is there a DOM in Python?

The DOM is a standard tree representation for XML data. The Document Object Model is being defined by the W3C in stages, or “levels” in their terminology. The Python mapping of the API is substantially based on the DOM Level 2 recommendation. DOM applications typically start by parsing some XML into a DOM.

What is Toprettyxml?

toprettyxml. n.toprettyxml(indent='\t',newl='\n') Returns a string, plain or Unicode, with the XML source for the subtree rooted at n, using indent to indent nested tags and newl to end lines. toxml. n.toxml( )


1 Answers

Try this:

parent.getElementsByTagName('Url')[0].childNodes[0].nodeValue
like image 165
Attila O. Avatar answered Oct 04 '22 00:10

Attila O.