minidom

Get Element value with minidom, Python

Hi Guys, I am creating a GUI frontend for the Eve Online API in Python. I have successfully pulled the XML data from their server. I am trying to grab the value from a node called "name" from xml.dom.minidom import parse dom = parse("C:\\eve.xml") name = dom.getElementsByTagName('name') print name This seems to find the node ok but...

Ignoring XML errors in Python

I am using XML minidom (xml.dom.minidom) in Python, but any error in the XML will kill the parser. Is it possible to ignore them, like a browser for example? I am trying to write a browser in Python, but it just throws an exception if the tags aren't fully compatible. ...

Python xml minidom. generate <text>Some text</text> element.

Hello! I have the following code. from xml.dom.minidom import Document doc = Document() root = doc.createElement('root') doc.appendChild(root) main = doc.createElement('Text') root.appendChild(main) text = doc.createTextNode('Some text here') main.appendChild(text) print doc.toprettyxml(indent='\t') The result is: <?xml version=...

Preserve order of attributes when modifying with minidom

Is there a way I can preserve the original order of attributes when processing XML with minidom? Say I have: <color red="255" green="255" blue="233" /> when I modify this with minidom the attributes are rearranged alphabetically blue, green, and red. I'd like to preserve the original order. I am processing the file by looping through t...

How to get whole text of an Element in xml.minidom?

I want to get the whole text of an Element to parse some xhtml: <div id='asd'> <pre>skdsk</pre> </div> begin E = div element on the above example, I want to get <pre>skdsk</pre> How? ...

Python: Using minidom to search for nodes with a certain text

I am currently faced with XML that looks like this: <ID>345754</ID> This is contained within a hierarchy. I have parsed the xml, and wish to find the ID node by searching on "345754". ...

Python: Stopping miniDOM from expanding escape sequences

When xml.dom.minidom parses a piece of xml, it automagically converts escape characters for greater than and less than into their visual representation. For example: >>> import xml.dom.minidom >>> s = "<example>4 &lt; 5</example>" >>> x = xml.dom.minidom.parseString(s) >>> x.firstChild.firstChild.data u'4 < 5' Does anyone know ...

xml.dom.minidom Document() in Python/django outputting memory location

I'm learning Python and django at the same time. I'm trying to create an xml document to return some XML from a view. I'm using the django development server at the moment and I keep getting this information spitting out in my views instead of the document I tried to create. Here's my code from django.http import HttpResponse from ...

Python urllib, minidom and parsing international characters

When I try to retrive information from google weather api with the followign url, http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de and then try to parse it with minidom, I get error that the document is not well formed. I use following code sock = urllib.urlopen(url) # above mentioned url doc = minidom.parse(sock) I t...

Reading XML using Python minidom and iterating over each node

I have an XML structure that looks like the following, but on a much larger scale: <root> <conference name='1'> <author>Bob</author> <author>Nigel</author> </conference> <conference name='2'> <author>Alice</author> <author>Mary</author> </conference> </root> For this, I used the following code: dom = parse(filepath) conference=dom.ge...

XML Parsing with Python and minidom

I'm using Python (minidom) to parse an XML file that prints a hierarchical structure that looks something like this (indentation is used here to show the significant hierarchical relationship): My Document Overview Basic Features About This Software Platforms Supported Instead, the program iterates multiple times over ...

XML attributes get sorted

When I create a document using the minidom, attributes get sorted alphabetically in the element. Take this example from here: from xml.dom import minidom # New document xml = minidom.Document() # Creates user element userElem = xml.createElement("user") # Set attributes to user element userElem.setAttribute("name", "Sergio Oliveira")...

How to set element's id in Python's xml.dom.minidom?

How to? Created a document and an element: import xml.dom.minidom as d a=d.Document() b=a.createElement('test') setIdAttribute doesn't work :( b.setIdAttribute('something') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/xml/dom/minidom.py", line 835, in setIdAttribute self.setI...

Get HTML links within a specified <table> using minidom

Hi All - I'm looking to use Python and xml.dom.minidom to get a list of links within a particular <table> specified by the table id. Based on some excellent advice, I'm trying to use the DOM instead of pattern matching. import urllib import xml.dom.minidom url = 'http://www.batstrading.com/market_data/shortsales' page = xml.dom.minido...

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 re...

Set a DTD using minidom in python.

I am trying to include a reference to a DTD in my XML doc using minidom. I am creating the document like: doc = Document() foo = doc.createElement('foo') doc.appendChild(foo) doc.toxml() This gives me: <?xml version="1.0" ?> <foo/> I need to get something like: <?xml version="1.0" ?> <!DOCTYPE something SYSTEM "http://www.path.t...

How to find elements by 'id' field in SVG file using Python

Below is an excerpt from an .svg file (which is xml): <text xml:space="preserve" style="font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sa...

Find element with attribute with minidom

Given <field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/> <field name="frame.time_relative" showname="Time since reference or first frame: 0.000008000 seconds" size="0" pos="0" show="0.000008000"/> <field name="frame.number" showname="Fr...

Update element values using xml.dom.minidom

Hello, I have an XML structure which looks similar to: <Store> <foo> <book> <isbn>123456</isbn> </book> <title>XYZ</title> <checkout>no</checkout> </foo> <bar> <book> <isbn>7890</isbn> </book> <title>XYZ2</title> <checkout>yes</checkout> </bar> </Store> Usin...

XML document being parsed as single element instead of sequence of nodes

Given xml that looks like this: <Store> <foo> <book> <isbn>123456</isbn> </book> <title>XYZ</title> <checkout>no</checkout> </foo> <bar> <book> <isbn>7890</isbn> </book> <title>XYZ2</title> <checkout>yes</checkout> </bar> </Store> I am getting this as my parsed xmldoc: >>> from xml.dom import minidom >>> xmldoc = minidom.parse('bar.x...