Search Results

Search found 37 results on 2 pages for 'minidom'.

Page 1/2 | 1 2  | Next Page >

  • python xml.dom.minidom.Attr question

    - by rudy
    Getting attributes using minidom in Python, one uses the "attributes" property. e.g. node.attributes["id"].value So if I have <a id="foo"></a>, that should give me "foo". node.attributes["id"] does not return the value of the named attribute, but an xml.dom.minidom.Attr instance. But looking at the help for Attr, by doing help('xml.dom.minidom.Attr'), nowhere is this magic "value" property mentioned. I like to learn APIs by looking at the type hierarchy, instance methods etc. Where did this "value" property come from?? Why is it not listed in the Attr class' page? The only data descriptors mentioned are isId, localName and schemaType. Its also not inherited from any superclasses. Since I'm new to Python, would some of the Python gurus enlighten?

    Read the article

  • Update element values using xml.dom.minidom

    - by amnesia-55
    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> Using xml.dom.minidom only (restrictions) i would like to 1)traverse through the XML file 2)Search/Get for particular element, depending on its parent Example: checkout element for author1, isbn for author2 3)Change/Set that element's value 4)Write the new XML structure to a file Can anyone help here? Thank you! UPDATE: This is what i have done till now import xml.dom.minidom checkout = "yes" def getLoneChild(node, tagname): assert ((node is not None) and (tagname is not None)) elem = node.getElementsByTagName(tagname) if ((elem is None) or (len(elem) != 1)): return None return elem def getLoneLeaf(node, tagname): assert ((node is not None) and (tagname is not None)) elem = node.getElementsByTagName(tagname) if ((elem is None) or (len(elem) != 1)): return None leaf = elem[0].firstChild if (leaf is None): return None return leaf.data def setcheckout(node, tagname): assert ((node is not None) and (tagname is not None)) child = getLoneChild(node, 'foo') Check = getLoneLeaf(child[0],'checkout') Check = tagname return Check doc = xml.dom.minidom.parse('test.xml') root = doc.getElementsByTagName('Store')[0] output = setcheckout(root, checkout) tmp_config = '/tmp/tmp_config.xml' fw = open(tmp_config, 'w') fw.write(doc.toxml()) fw.close()

    Read the article

  • Integers in TextNodes w/ Python minidom

    - by PylonsN00b
    I am working on an API using SOAP and WSDL. The WSDL expects integers to come through. I am fairly new to ALL of this, and constructing XML in Python. I have chosen to use minidom to create my SOAP message. So using minidom, to get a value into a node I found I have to do this: weight_node = xml_file.createElement("web:Weight") weight_contents = xml_file.createTextNode(weight) weight_node.appendChild(weight_contents) So say weight needs to go in as an integer and IS an integer. The function is 'createTextNode' does this mean its going to be text, or what I put in there has to be text? Again I am fairly new to all of this. So if what I have explained seems way off base, please speak up.

    Read the article

  • Get Element value with minidom, Python

    - by Eef
    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 the output is below: [<DOM Element: name at 0x11e6d28>] How could I get it to print the value of the node? Cheers

    Read the article

  • Get node name with minidom

    - by Alex
    Is it possible to get the name of a node using minidom? for example i have a node: <heading><![CDATA[5 year]]></heading> what i'm trying to do is store the value heading so that i can use it as a key in a dictionary, the closest i can get is something like [<DOM Element: heading at 0x11e6d28>] i'm sure i'm overlooking something very simple here, thanks!

    Read the article

  • Hudson XML error-- No module named dom.minidom

    - by Arnab Sen Gupta
    I am trying to send a simple XML file of the format given in http://wiki.hudson-ci.org/display/HUDSON/Monitoring+external+jobs . I was able to send it easily and was getting desired result!! Then I tried to build this XML file using python script and it was giving me the exact file that I wanted without any problem. But when I tried to run this and send it to Hudson, I was getting the error - "No module named dom.minidom" . I checked again by executing in Python IDLE and it ws working fine but when I tried to send it again, I was getting the same error.. plz help..

    Read the article

  • Python minidom and UTF-8 encoded XML with hash references

    - by Jakob Simon-Gaarde
    Hi I am experiencing some difficulty in my home project where I need to parse a SOAP request. The SOAP is generated with gSOAP and involves string parameters with special characters like the danish letters "æøå". gSOAP builds SOAP requests with UTF-8 encoding by default, but instead of sending the special chatacters in raw format (ie. bytes C3A6 for the special character "æ") it sends what I think is called character hash references (ie. &#195;&#166;). I don't completely understand why gSOAP does it this way as I can see that it has marked the incomming payload as being UTF-8 encoded anyway (Content-Type: text/xml; charset=utf-8), but this is besides the question (I think). Anyway I guess gSOAP probably is obeying transport rules, or what? When I parse the request from gSOAP in python with xml.dom.minidom.parseString() I get element values as unicode objects which is fine, but the character hash references are not decoded as UTF-8 character codes. It unescapes the character hash references, but does not decode the string afterwards. In the end I have a unicode string object with UTF-8 encoding: So if the string "æble" is contained in the XML, it comes like this in the request: "&#195;&#166;ble" After parsing the XML the unicode string in the DOM Text Node's data member looks like this: u'\xc3\xa6ble' I would expect it to look like this: u'\xe6ble' What am I doing wrong? Should I unescape the SOAP XML before parsing it, or is it somewhere else I should be looking for the solution, maybe gSOAP? Thanks in advance. Best regards Jakob Simon-Gaarde

    Read the article

  • Find element with attribute with minidom

    - by Xster
    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="Frame Number: 2" size="0" pos="0" show="2"/> <field name="frame.pkt_len" showname="Packet Length: 1506 bytes" hide="yes" size="0" pos="0" show="1506"/> <field name="frame.len" showname="Frame Length: 1506 bytes" size="0" pos="0" show="1506"/> <field name="frame.cap_len" showname="Capture Length: 1506 bytes" size="0" pos="0" show="1506"/> <field name="frame.marked" showname="Frame is marked: False" size="0" pos="0" show="0"/> <field name="frame.protocols" showname="Protocols in frame: eth:ip:tcp:http:data" size="0" pos="0" show="eth:ip:tcp:http:data"/> How do I get the field with name="frame.len" right away without iterating through every tag and checking the attributes?

    Read the article

  • How can I disable 'output escaping' in minidom

    - by William
    I'm trying to build an xml document from scratch using xml.dom.minidom. Everything was going well until I tried to make a text node with a ® (Registered Trademark) symbol in. My objective is for when I finally hit print mydoc.toxml() this particular node will actually contain a ® symbol. First I tried: import xml.dom.minidom as mdom data = '®' which gives the rather obvious error of: File "C:\src\python\HTMLGen\test2.py", line 3 SyntaxError: Non-ASCII character '\xae' in file C:\src\python\HTMLGen\test2.py on line 3, but no encoding declared; see http://www.python.or g/peps/pep-0263.html for details I have of course also tried changing the encoding of my python script to 'utf-8' using the opening line comment method, but this didn't help. So I thought import xml.dom.minidom as mdom data = '&#174;' #Both accepted xml encodings for registered trademark data = '&reg;' text = mdom.Text() text.data = data print data print text.toxml() But because when I print text.toxml(), the ampersands are being escaped, I get this output: &reg; &amp;reg; My question is, does anybody know of a way that I can force the ampersands not to be escaped in the output, so that I can have my special character reference carry through to the XML document? Basically, for this node, I want print text.toxml() to produce output of &reg; or &#174; in a happy and cooperative way! EDIT 1: By the way, if minidom actually doesn't have this capacity, I am perfectly happy using another module that you can recommend which does. EDIT 2: As Hugh suggested, I tried using data = u'®' (while also using data # -*- coding: utf-8 -*- Python source tags). This almost helped in the sense that it actually caused the ® symbol itself to be outputted to my xml. This is actually not the result I am looking for. As you may have guessed by now (and perhaps I should have specified earlier) this xml document happens to be an HTML page, which needs to work in a browser. So having ® in the document ends up causing rubbish in the browser (® to be precise!). I also tried: data = unichr(174) text.data = data.encode('ascii','xmlcharrefreplace') print text.toxml() But of course this lead to the same origional problem where all that happens is the ampersand gets escaped by .toxml(). My ideal scenario would be some way of escaping the ampersand so that the XML printing function won't "escape" it on my behalf for the document (in other words, achieving my original goal of having &reg; or &#174; appear in the document). Seems like soon I'm going to have to resort to regular expressions! EDIT 2a: Or perhaps not. Seems like getting my html meta information correct <META http-equiv="Content-Type" Content="text/html; charset=UTF-8"> could help, but I'm not sure yet how this fits in with the xml structure...

    Read the article

  • Processing RSS/RDF via xml.dom.minidom

    - by Bill
    I'm trying to process a delicious rss feed via python. Here's a sample: ... <item rdf:about="http://weblist.me/"> <title>WebList - The Place To Find The Best List On The Web</title> <dc:date>2009-12-24T17:46:14Z</dc:date> <link>http://weblist.me/</link> ... </item> <item rdf:about="http://thumboo.com/"> <title>Thumboo! Free Website Thumbnails and PHP Script to Generate Web Screenshots</title> <dc:date>2006-10-24T18:11:32Z</dc:date> <link>http://thumboo.com/</link> ... The relevant code is: def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc dom = xml.dom.minidom.parse(file) items = dom.getElementsByTagName("item") for i in items: title = i.getElementsByTagName("title") print getText(title) I would think this would print out each title, but instead I get basically get blank output. I'm sure I'm doing something stupid wrong, but no idea what?

    Read the article

  • XML - python prints extra lines

    - by horse
    `from xml import xpath from xml.dom import minidom xmldata = minidom.parse('model.xml').documentElement for maks in xpath.Evaluate('/cacti/results/maks/text()', xmldata): print maks.nodeValue ` and I get result: 85603399.14 398673062.66 95785523.81 But I needed to be: 85603399.14 NO SPACE 398673062.66 NO SPACE 95785523.81 Can somebody help me, i new at programing :( ?

    Read the article

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

    - by Rob Carr
    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.xml') >>> xmldoc.toxml() u'<?xml version="1.0" ?><Store>\n<foo>\n<book>\n<isbn>123456</isbn>\n</book>\n<t itle>XYZ</title>\n<checkout>no</checkout>\n</foo>\n<bar>\n<book>\n<isbn>7890</is bn>\n</book>\n<title>XYZ2</title>\n<checkout>yes</checkout>\n</bar>\n</Store>' Is there an easy way to pre-process this document so that when it is parsed, it isn't parsed as a single xml element?

    Read the article

  • Converting a Doc object into a string in python

    - by Sam
    I'm using minidom to parse through an xml document. I took the data with yum tags and stored them in a list and calculated the frequency of the words. However, its not storing or reading them as strings in the list. Is there another way to do it? Right now this is what I have: yumNodes = [node for node in doc.getElementsByTagName("yum")] for node in yumNodes: yumlist.append(t.data for t in node.childNodes if t.nodeType == t.TEXT_NODE) for ob in yumlist: for o in ob: if word not in freqDict: freqDict[word] = 1 else: freqDict[word] += 1

    Read the article

  • Decoding not reversing unicode encoding in Django/Python

    - by PhilGo20
    Ok, I have a hardcoded string I declare like this name = u"Par Catégorie" I have a # -- coding: utf-8 -- magic header, so I am guessing it's converted to utf-8 Down the road it's outputted to xml through xml_output.toprettyxml(indent='....', encoding='utf-8') And I get a UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128) Most of my data is in French and is ouputted correctly in CDATA nodes, but that one harcoded string keep ... I don't see why an ascii codec is called. what's wrong ?

    Read the article

  • In python writing from XML to CSV, encoding error

    - by user574435
    Hi, I am trying to convert an XML file to CSV, but the encoding of the XML ("ISO-8859-1") apparently contains characters that are not in the ascii codec which Python uses to write rows. I get the error: Traceback (most recent call last): File "convert_folder_to_csv_PLAYER.py", line 139, in <module> xml2csv_PLAYER(filename) File "convert_folder_to_csv_PLAYER.py", line 121, in xml2csv_PLAYER fout.writerow(row) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 4: ordinal not in range(128) I have tried opening the file as follows: dom1 = parse(input_filename.encode( "utf-8" ) ) and I have tried replacing the \xe1 character in each row before it is written. Any suggestions?

    Read the article

  • How to parse strings representing xml.dom.minidom nodes in python?

    - by Francis Davey
    I have a collection of nodes xml.dom.Node objects created using xml.dom.minidom. I store them (individually) in a database by converting them to a string using the toxml() method of a the Node object. The problem is that I'd sometimes like to be able to convert them back to the appropriate Node object using a parser of some kind. As far as I can see the various libraries shipped with python use Expat which won't parse a string like '' or indeed anything which is not a correct xml string. So, does anyone have any ideas? I realise I could pickle the nodes in some way and then unpickle them, but that feels unpleasant and I'd much rather be storing in a form I can read for maintenance purposes. Surely there is something that will do this?

    Read the article

  • [Python]Xml add a node from another xml document

    - by michele
    Hi, I have two xml file: 1)model.xml 2)projectionParametersTemplate.xml I want to extract from 1) Algorithm Node with his child and put it in 2) I have wrote this code but it doesn't function. from xml.dom.minidom import Document from xml.dom import minidom xmlmodel=minidom.parse("/home/michele/Scrivania/d/model.xml") xmltemplate=minidom.parse("/home/michele/Scrivania/d/projectionParametersTemplate.xml") for Node in xmlmodel.getElementsByTagName("Algorithm"): print "\nNode: "+str(Node) for Node2 in xmltemplate.getElementsByTagName("ProjectionParameters"): print "\nNode2: "+str(Node2) Node2.appendChild(Node) This is model.xml link text This is projectionParametersTemplate.xml link text Thanks a lot.

    Read the article

  • Modify an XML file in Python

    - by michele
    Hi, I have two file. I have to modify the file one in a particular node and add in a list of child. The list is in the file2. Can I do it, and how? from xml.dom.minidom import Document from xml.dom import minidom file1=modificare.xml file2=sorgente.xml xmldoc=minidom.parse(file1) for Node in xmldoc.getElementsByTagName("Sampler"): # put in the file2 content Thanks a lot.

    Read the article

  • How to convert XML to JSON in Python?

    - by Geuis
    I'm doing some work on App Engine and I need to convert an XML document being retrieved from a remote server into an equivalent JSON object. I'm using xml.dom.minidom to parse the XML data being returned by urlfetch. I'm also trying to use django.utils.simplejson to convert the parsed XML document into JSON. I'm completely at a loss as to how to hook the two together. Below is the code I more or less have been tinkering with. If anyone can put A & B together, I would be SO greatful. I'm freaking lost. from xml.dom import minidom from django.utils import simplejson as json #pseudo code that returns actual xml data as a string from remote server. result = urlfetch.fetch(url,'','get'); dom = minidom.parseString(result.content) json = simplejson.load(dom) self.response.out.write(json)

    Read the article

  • How to write an XML file without header in Python?

    - by Nico
    Hi, when using Python's stock XML tools such as xml.dom.minidom for XML writing, a file would always start off like <?xml version="1.0"?> [...] While this is perfectly legal XML code, and it's even recommended to use the header, I'd like to get rid of it as one of the programs I'm working with has problems here. I can't seem to find the appropriate option in xml.dom.minidom, so I wondered if there are other packages which do allow to neglect the header. Cheers, Nico

    Read the article

  • Optimising RSS parsing on App Engine to avoid high CPU warnings

    - by Danny Tuppeny
    I'm pulling some RSS feeds into a datastore in App Engine to serve up to an iPhone app. I use cron to schedule updating the RSS every x minutes. Each task only parses one RSS feed (which has 15-20 items). I frequently get warnings about high CPU usage in the App Engine dashboard, so I'm looking for ways to optimise my code. Currently, I use minidom (since it's already there on App Engine), but I suspect it's not very efficient! Here's the code: dom = minidom.parseString(urlfetch.fetch(url).content) if dom: items = [] for node in dom.getElementsByTagName('item'): item = RssItem( key_name = self.getText(node.getElementsByTagName('guid')[0].childNodes), title = self.getText(node.getElementsByTagName('title')[0].childNodes), description = self.getText(node.getElementsByTagName('description')[0].childNodes), modified = datetime.now(), link = self.getText(node.getElementsByTagName('link')[0].childNodes), categories = [self.getText(category.childNodes) for category in node.getElementsByTagName('category')] ); items.append(item); db.put(items); def getText(self, nodelist): rc = '' for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc There isn't much going on, but the scripts often take 2-6 seconds CPU time, which seems a bit excessive for looping through 20ish items and reading a few attributes. What can I do to make this faster? Is there anything particularly bad in the above code, or should I change to another way of parsing? Are there are any libraries (that work on App Engine) that would be better, or would I be better parsing the RSS myself?

    Read the article

  • How do I render *parts* of a svg file?

    - by Fake Code Monkey Rashid
    Hello good people! :) I want to render parts of a svg file by name but for the life of me I cannot figure out how to do so (using python + gtk). Here's the svg file in question: http://david.bellot.free.fr/svg-cards/files/SVG-cards-2.0.1.tar.gz On his site, David, says: You can draw a card either by rendering the file onto a pixmap and clipping each card manually or by using the card's name through a DOM interface. All cards are embedded into a SVG group. I don't know what he means by a DOM interface. I have done some searching and the best result I found that seems to fit what I want to do is: QSvgRenderer *renderer = new QSvgRenderer(QLatin1String("SvgCardDeck.svg")); QGraphicsSvgItem *black = new QGraphicsSvgItem(); QGraphicsSvgItem *red = new QGraphicsSvgItem(); black->setSharedRenderer(renderer); black->setElementId(QLatin1String("black_joker")); red->setSharedRenderer(renderer); red->setElementId(QLatin1String("red_joker")); Notice however that it is for Qt and is not even written in python. This is what I have so far: #!/usr/bin/env python from __future__ import absolute_import import cairo import gtk import rsvg from xml import xpath from xml.dom import minidom window = gtk.Window() window.set_title("Foo") window.set_size_request(256, 256) window.set_property("resizable", False) window.set_position(gtk.WIN_POS_CENTER) window.connect("destroy", gtk.main_quit) window.show() document = minidom.parse("cards.svg") element = xpath.Evaluate("//*[@id='1_club']", document)[0] xml = element.toxml() svg = rsvg.Handle() svg.write(xml) pixbuf = svg.get_pixbuf() image = gtk.Image() image.set_from_pixbuf(pixbuf) image.show() window.add(image) gtk.main() It doesn't work, of course. What am I missing?

    Read the article

  • Xen won't start after it had been working

    - by Paul Tomblin
    I've been setting up this Debian Stable system with a dom0 and 3 domUs. It was working fine for several days, and I'm almost ready to deploy it to the rack. But last night I shut it down with all three domUs still running for the first time, and today when I started it up, xend won't start. In /var/log/messages, I have: Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: blktapctrl: v1.0.0 Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Found driver: [raw image (aio)] Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Found driver: [raw image (sync)] Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Found driver: [vmware image (vmdk)] Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Found driver: [ramdisk image (ram)] Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Found driver: [qcow disk (qcow)] Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: couldn't find device number for 'blktap0' Apr 18 13:01:33 xen-test BLKTAPCTRL[4248]: Unable to start blktapctrl and in /var/log/xen/xend.log, I have this: [2010-04-18 12:46:32 3523] INFO (SrvDaemon:219) Xend exited with status 1. [2010-04-18 13:01:34 4255] INFO (SrvDaemon:331) Xend Daemon started [2010-04-18 13:01:34 4255] INFO (SrvDaemon:335) Xend changeset: unavailable. [2010-04-18 13:01:34 4255] INFO (SrvDaemon:342) Xend version: Unknown. [2010-04-18 13:01:34 4255] ERROR (SrvDaemon:353) Exception starting xend (no element found: line 1, column 0) Traceback (most recent call last): File "/usr/lib/xen-3.2-1/lib/python/xen/xend/server/SrvDaemon.py", line 345, in run servers = SrvServer.create() File "/usr/lib/xen-3.2-1/lib/python/xen/xend/server/SrvServer.py", line 251, in create root.putChild('xend', SrvRoot()) File "/usr/lib/xen-3.2-1/lib/python/xen/xend/server/SrvRoot.py", line 40, in __init__ self.get(name) File "/usr/lib/xen-3.2-1/lib/python/xen/web/SrvDir.py", line 82, in get val = val.getobj() File "/usr/lib/xen-3.2-1/lib/python/xen/web/SrvDir.py", line 52, in getobj File "/usr/lib/xen-3.2-1/lib/python/xen/xend/server/SrvNode.py", line 30, in _ _init__ self.xn = XendNode.instance() File "/usr/lib/xen-3.2-1/lib/python/xen/xend/XendNode.py", line 709, in instance inst = XendNode() File "/usr/lib/xen-3.2-1/lib/python/xen/xend/XendNode.py", line 164, in __init__ saved_pifs = self.state_store.load_state('pif') File "/usr/lib/xen-3.2-1/lib/python/xen/xend/XendStateStore.py", line 104, in load_state dom = minidom.parse(xml_path) File "/usr/lib/python2.5/xml/dom/minidom.py", line 1915, in parse return expatbuilder.parse(file) File "/usr/lib/python2.5/xml/dom/expatbuilder.py", line 924, in parse result = builder.parseFile(fp) File "/usr/lib/python2.5/xml/dom/expatbuilder.py", line 211, in parseFile parser.Parse("", True) ExpatError: no element found: line 1, column 0 [2010-04-18 13:01:34 4253] INFO (SrvDaemon:219) Xend exited with status 1. Any clues as to what might be going wrong?

    Read the article

  • Celery - minimize memory consuption

    - by Andrew
    We have ~300 celeryd processes running under Ubuntu 10.4 64-bit , in idle every process takes ~19mb RES, ~174mb VIRT, thus - it's around 6GB of RAM in idle for all processes. In active state - process takes up to 100mb of RES and ~300mb VIRT Every process uses minidom(xml files are < 500kb, simple structure) and urllib. Quetions is - how can we decrease RAM consuption - at least for idle workers, probably some celery or python options may help? How to determine which part takes most of memory?

    Read the article

1 2  | Next Page >