By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

Plain old SAX and minidom useable? But how then?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.