Plain old SAX and minidom useable? But how then?

Dobedani dobedani at gmx.net
Wed Aug 1 15:04:05 CEST 2007


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... at web.de> wrote:
> 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/whitepapers/minidom.html
>
> Maybe that helps?
>
> Stefan





More information about the Python-list mailing list