473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Plain old SAX and minidom useable? But how then?

Dear All,

I guess I don't know where to look for the right information. I hope
you guys can help me on the way. I want to retrieve a string from an
XML-file. If Python were to have XPath available, my problem would be
solved. The xquery string would be enough and I have already obtained
that the string. The problem is that I cannot use any add-on - like
xmllib, sax2 or elementtree - as my customers only have the so-called
stock Python install - i.e. version 2.4.1. I've seen some posts from
2½ years ago by Nelson Minar and also by Uche Ogbuji who wrote:
"Nelson says: There's the stock Python install, which barely does
anything [for XML]. That's overstated. Plain old SAX and minidom may
not be ideal, but they're useable."

Please: where then can I find examples of such use? If I cannot use
xpath, I would not mind to browse a bit - e.g. using functions like
getElementByTag() but I don't even know how to use those. TIA

Kind regards,
Dobedani

Aug 1 '07 #1
2 1419
Hi,

calm down, minidom is not easy to use, but it can solve your problem.

Dobedani wrote:
I guess I don't know where to look for the right information. I hope
you guys can help me on the way. I want to retrieve a string from an
XML-file. If Python were to have XPath available, my problem would be
solved. The xquery string would be enough and I have already obtained
that the string. The problem is that I cannot use any add-on - like
xmllib, sax2 or elementtree - as my customers only have the so-called
stock Python install - i.e. version 2.4.1.
Too bad, that rules out lxml.etree (which has XPath and loads of other goodies).

Please: where then can I find examples of such use? If I cannot use
xpath, I would not mind to browse a bit - e.g. using functions like
getElementByTag() but I don't even know how to use those. TIA
Try one of these (I looked for "minidom example"):

http://www.faqs.org/docs/diveintopython/kgp_parse.html
http://docs.python.org/lib/dom-example.html
http://www.cutthecrap.biz/software/w...s/minidom.html

Maybe that helps?

Stefan
Aug 1 '07 #2
Darsten and Stefan,

Yeah, thank you very much! I actually found a good example at
http://www.python.org/doc/2.4/lib/dom-example.html

Your input was also helpful, so now I have been able to "walk" through
the XML and to retrieve the text strings I need:

doc = parse(configfile);
elems = doc.getElementsByTagName("Environment")
for elem in elems:
name = elem.getElementsByTagName("Name")[0];
if getText(name.childNodes) == "workspace":
...

with getText as defined on the webpage referenced above.

Kind regards,
Dobedani
http://www.python.org/doc/2.4/lib/dom-example.html

On Aug 1, 2:26 pm, Stefan Behnel <stefan.behnel-n05...@web.dewrote:
Hi,

calm down, minidom is not easy to use, but it can solve your problem.

Dobedani wrote:
I guess I don't know where to look for the right information. I hope
you guys can help me on the way. I want to retrieve a string from an
XML-file. If Python were to have XPath available, my problem would be
solved. The xquery string would be enough and I have already obtained
that the string. The problem is that I cannot use any add-on - like
xmllib, sax2 or elementtree - as my customers only have the so-called
stock Python install - i.e. version 2.4.1.

Too bad, that rules out lxml.etree (which has XPath and loads of other goodies).
Please: where then can I find examples of such use? If I cannot use
xpath, I would not mind to browse a bit - e.g. using functions like
getElementByTag() but I don't even know how to use those. TIA

Try one of these (I looked for "minidom example"):

http://www.faqs.org/docs/diveintopython/kgp_parse.html
http://docs.python.org/lib/dom-example.html
http://www.cutthecrap.biz/software/w...s/minidom.html

Maybe that helps?

Stefan

Aug 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: xtian | last post by:
Hi - I'm doing some data conversion with minidom (turning a csv file into a specific xml format), and I've hit a couple of small problems. 1: The output format has a header with some xml that...
2
by: Anthony Liu | last post by:
I copy-pasted the following sample xml document from http://slis-two.lis.fsu.edu/~xml/sample.html and saved it as samplexml.xml. Please note that I removed the following line <!DOCTYPE...
5
by: Skip Montanaro | last post by:
I'd like to compare two xml.dom.minidom objects, but the naive attempt fails: >>> import xml.dom.minidom >>> d1 = xml.dom.minidom.parse("ES.xml") >>> d2 = xml.dom.minidom.parse("ES.xml") >>> d1...
5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
1
by: Paul Kozik | last post by:
I am trying to write a script that reads an XML file (using the minidom module), makes an edit to a few attributes, then saves it back. If I use minidom.Document() to create the xml file, then...
18
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i...
0
by: Gary | last post by:
Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The...
3
by: aine_canby | last post by:
Hi, I'm working with a number of scripts which were written years ago for my company for Python 2.2, and I'd like to update for Python 2.5. I have written a script to add # -*- coding: cp1252...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.