Re: REALLY simple xml reader

2008-02-02 Thread Stefan Behnel
Steven D'Aprano wrote: > On Fri, 01 Feb 2008 07:51:56 +1100, Ben Finney wrote: > >> Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>> On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: >>> Quite apart from a human thinking it's pretty or not pretty, it's *not valid XML* if the XML de

Re: REALLY simple xml reader

2008-02-02 Thread Steven D'Aprano
On Fri, 01 Feb 2008 07:51:56 +1100, Ben Finney wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: >> >> > Quite apart from a human thinking it's pretty or not pretty, it's >> > *not valid XML* if the XML declaration isn't immediately a

Re: REALLY simple xml reader

2008-02-02 Thread Steven D'Aprano
On Sat, 02 Feb 2008 07:24:36 +0100, Stefan Behnel wrote: > Steven D'Aprano wrote: >> The same way it knows that "> encoding. If the parser knows that the hex bytes >> >> 3c 3f 78 6d 6c >> >> (or 3c 00 3f 00 78 00 6d 00 6c 00 if you prefer UTF-16, and feel free >> to swap the byte order) >> >> m

Re: REALLY simple xml reader

2008-02-01 Thread Stefan Behnel
Steven D'Aprano wrote: > The same way it knows that " encoding. If the parser knows that the hex bytes > > 3c 3f 78 6d 6c > > (or 3c 00 3f 00 78 00 6d 00 6c 00 if you prefer UTF-16, and feel free to > swap the byte order) > > mean " > then it can equally know that bytes > > 20 09 0a > > a

Re: REALLY simple xml reader

2008-02-01 Thread Steven D'Aprano
On Thu, 31 Jan 2008 18:35:17 +0100, Stefan Behnel wrote: > Hi, > > Steven D'Aprano wrote: >> On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: >> >>> Quite apart from a human thinking it's pretty or not pretty, it's *not >>> valid XML* if the XML declaration isn't immediately at the start of

Re: REALLY simple xml reader

2008-01-31 Thread Stefan Behnel
Ivan Illarionov wrote: >> Also, for XML documents, they were probably thinking that the >> documents will be machine-generated most of the time. As far as I can >> tell, they were right in that. > > If anybody has to deal with human-generated XML/HTML in Python it may > be better to use something

Re: REALLY simple xml reader

2008-01-31 Thread Ivan Illarionov
> Also, for XML documents, they were probably thinking that the > documents will be machine-generated most of the time. As far as I can > tell, they were right in that. If anybody has to deal with human-generated XML/HTML in Python it may be better to use something like http://www.crummy.com/softw

Re: REALLY simple xml reader

2008-01-31 Thread Ricardo Aráoz
Diez B. Roggisch wrote: > Ricardo Aráoz schrieb: >> Diez B. Roggisch wrote: >>> Ricardo Aráoz schrieb: Thanks Ivan, it seems a elegant API, and easy to use. I tried to play a little with it but unfortunately could not get it off the ground. I kept getting >>> root = et.fromstring

Re: REALLY simple xml reader

2008-01-31 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: > > > Quite apart from a human thinking it's pretty or not pretty, it's *not > > valid XML* if the XML declaration isn't immediately at the start of the > > document http://www.w3.org/TR/xml/#sec-p

Re: REALLY simple xml reader

2008-01-31 Thread Stefan Behnel
Stefan Behnel wrote: > Steven D'Aprano wrote: >> On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: >> >>> Quite apart from a human thinking it's pretty or not pretty, it's *not >>> valid XML* if the XML declaration isn't immediately at the start of the >>> document http://www.w3.org/TR/xml/#sec

Re: REALLY simple xml reader

2008-01-31 Thread Stefan Behnel
Hi, Steven D'Aprano wrote: > On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: > >> Quite apart from a human thinking it's pretty or not pretty, it's *not >> valid XML* if the XML declaration isn't immediately at the start of the >> document http://www.w3.org/TR/xml/#sec-prolog-dtd>. Many XML

Re: REALLY simple xml reader

2008-01-31 Thread Diez B. Roggisch
Steven D'Aprano schrieb: > On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: > >> Quite apart from a human thinking it's pretty or not pretty, it's *not >> valid XML* if the XML declaration isn't immediately at the start of the >> document http://www.w3.org/TR/xml/#sec-prolog-dtd>. Many XML >>

Re: REALLY simple xml reader

2008-01-31 Thread Steven D'Aprano
On Fri, 01 Feb 2008 00:40:01 +1100, Ben Finney wrote: > Quite apart from a human thinking it's pretty or not pretty, it's *not > valid XML* if the XML declaration isn't immediately at the start of the > document http://www.w3.org/TR/xml/#sec-prolog-dtd>. Many XML > parsers will (correctly) reject

Re: REALLY simple xml reader

2008-01-31 Thread Steve Holden
Ben Finney wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > >> Diez B. Roggisch wrote: >>> Ricardo Aráoz schrieb: doc = """ >>> It's not allowed to have a newline before the >>> >>> Put it on the line above, and things will work. >>> >> If you don't think that looks pretty enough ju

Re: REALLY simple xml reader

2008-01-31 Thread Ben Finney
Steve Holden <[EMAIL PROTECTED]> writes: > Diez B. Roggisch wrote: > > Ricardo Aráoz schrieb: > >> doc = """ > >> > > > > It's not allowed to have a newline before the > > > > Put it on the line above, and things will work. > > > If you don't think that looks pretty enough just escape the first

Re: REALLY simple xml reader

2008-01-31 Thread Steve Holden
Diez B. Roggisch wrote: > Ricardo Aráoz schrieb: >> Diez B. Roggisch wrote: >>> Ricardo Aráoz schrieb: Thanks Ivan, it seems a elegant API, and easy to use. I tried to play a little with it but unfortunately could not get it off the ground. I kept getting >>> root = et.fromstring

Re: REALLY simple xml reader

2008-01-31 Thread Diez B. Roggisch
Ricardo Aráoz schrieb: > Diez B. Roggisch wrote: >> Ricardo Aráoz schrieb: >>> Thanks Ivan, it seems a elegant API, and easy to use. >>> I tried to play a little with it but unfortunately could not get it off >>> the ground. I kept getting >> root = et.fromstring(doc) >>> Traceback (most recent

Re: REALLY simple xml reader

2008-01-31 Thread Ricardo Aráoz
Diez B. Roggisch wrote: > Ricardo Aráoz schrieb: >> Thanks Ivan, it seems a elegant API, and easy to use. >> I tried to play a little with it but unfortunately could not get it off >> the ground. I kept getting > root = et.fromstring(doc) >> Traceback (most recent call last): >> File "", line

Re: REALLY simple xml reader

2008-01-31 Thread Diez B. Roggisch
Ricardo Aráoz schrieb: > Ivan Illarionov wrote: > from xml.etree import ElementTree as et > from decimal import Decimal > > root = et.parse('file/with/your.xml') > debits = dict((debit.attrib['category'], > Decimal(debit.find('amount').text)) for debit in root.findall('debi

Re: REALLY simple xml reader

2008-01-31 Thread Ricardo Aráoz
Ivan Illarionov wrote: from xml.etree import ElementTree as et from decimal import Decimal root = et.parse('file/with/your.xml') debits = dict((debit.attrib['category'], Decimal(debit.find('amount').text)) for debit in root.findall('debit')) for cat, amount

Re: REALLY simple xml reader

2008-01-30 Thread Ivan Illarionov
>>> from xml.etree import ElementTree as et >>> from decimal import Decimal >>> >>> root = et.parse('file/with/your.xml') >>> debits = dict((debit.attrib['category'], >>> Decimal(debit.find('amount').text)) for debit in root.findall('debit')) >>> >>> for cat, amount in debits.items(): ... print

Re: REALLY simple xml reader

2008-01-29 Thread Stefan Behnel
Hi, Ricardo Aráoz wrote: > 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 s from > s (any category) but not s. > > doc = """ > > > expenses: jan

Re: REALLY simple xml reader

2008-01-29 Thread Ricardo Aráoz
> What about : > > doc = """ > >99 > > >42 > > """ That's not an XML document, so what about it? Stefan -- 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 fo

Re: REALLY simple xml reader

2008-01-29 Thread Stefan Behnel
Ricardo Aráoz wrote: > What about : > > doc = """ > >99 > > >42 > > """ That's not an XML document, so what about it? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: REALLY simple xml reader

2008-01-29 Thread Ricardo Aráoz
Diez B. Roggisch wrote: > Simon Pickles schrieb: >> Hi >> >> Can anyone suggest a really simple XML reader for python? I just want to >> be able to do something like this: >> >> xmlDoc = xml.open("file.xml") >> element = xmlDoc.GetElement(&q

Re: REALLY simple xml reader

2008-01-27 Thread Navtej Singh
check the implementation of XMLNode class here http://hsivonen.iki.fi/group-feed/flickrapi.py HTH N On Jan 27, 2008 11:05 PM, Simon Pickles <[EMAIL PROTECTED]> wrote: > Hi > > Can anyone suggest a really simple XML reader for python? I just want to > be able to do something lik

Re: REALLY simple xml reader

2008-01-27 Thread Mark Tolonen
"Simon Pickles" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi > > Can anyone suggest a really simple XML reader for python? I just want to > be able to do something like this: > > xmlDoc = xml.open("file.xml") > element = xmlDoc.

Re: REALLY simple xml reader

2008-01-27 Thread Diez B. Roggisch
Simon Pickles schrieb: > Hi > > Can anyone suggest a really simple XML reader for python? I just want to > be able to do something like this: > > xmlDoc = xml.open("file.xml") > element = xmlDoc.GetElement("foo/bar") > > ... to read the

REALLY simple xml reader

2008-01-27 Thread Simon Pickles
Hi Can anyone suggest a really simple XML reader for python? I just want to be able to do something like this: xmlDoc = xml.open("file.xml") element = xmlDoc.GetElement("foo/bar") ... to read the value of: 42 Thanks Simon -- Linux user #458601 - http://counter