REALLY simple xml reader

Ricardo Aráoz ricaraoz at
Tue Jan 29 15:53:44 CET 2008

> What about :
> doc = """
> <moo>
>    <bar>99</bar>
> </moo>
> <foo>
>    <bar>42</bar>
> </foo>
> """

That's not an XML document, so what about it?



Ok Stefan, I will pretend it was meant in good will.

I don't know zit about xml, but I might need to, and I am saving the
thread for when I need it. So I looked around and found some 'real'
XML document (see below). The question is, how to access <amount>s from
<debit>s (any category) but not <deposit>s.
Probably my previous example was not properly stated, what I meant to
convey is two substructures (namespaces, or whatever you call them in
XML) which have the same 'properties' <moo><bar> is not the same as
<foo><bar> as <debit><amount> is not the same as <deposit><amount>.
The examples given by Diez and Mark, though useful, don't seem to
address the problem.
Thanks for your help.

doc = """
<?xml version="1.0"?>
<checkbook balance-start="2460.62">
<title>expenses: january 2002</title>

  <debit category="clothes">
    <payto>Walking Store</payto>

  <deposit category="salary">
    <payor>Bob's Bolts</payor>

  <debit category="withdrawal">
    <description>pocket money</description>

  <debit category="savings">

  <debit category="medical" check="855">
    <payto>Boston Endodontics</payto>

  <debit category="supplies">
    <payto>Exxon Saugus</payto>

  <debit category="car">
    <payto>Honda North</payto>
    <description>car repairs</description>

  <debit category="food">
    <payto>Johnny Rockets</payto>

More information about the Python-list mailing list