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 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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |