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 ?xml is ?xml before it sees the 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

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 at the start

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 declaration isn't

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 the

Re: REALLY simple xml reader

2008-02-01 Thread Stefan Behnel
Steven D'Aprano wrote: The same way it knows that ?xml is ?xml before it sees the 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 ?xml then it can equally know that

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 in debits.items(): ... print

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('debit')) for cat, amount in

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 input, line 1, in

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 call last): File

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(doc) Traceback (most

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 = ?xml version=1.0? It's not allowed to have a newline before the ?xml ... 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
Ben Finney wrote: Steve Holden [EMAIL PROTECTED] writes: Diez B. Roggisch wrote: Ricardo Aráoz schrieb: doc = ?xml version=1.0? It's not allowed to have a newline before the ?xml ... Put it on the line above, and things will work. If you don't think that looks pretty enough just

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 URL:http://www.w3.org/TR/xml/#sec-prolog-dtd. Many XML parsers will (correctly) reject

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 URL:http://www.w3.org/TR/xml/#sec-prolog-dtd. Many XML

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 URL:http://www.w3.org/TR/xml/#sec-prolog-dtd. Many XML

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

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

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(doc) Traceback (most

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

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 like

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 '%s: %s' % (cat,

Re: REALLY simple xml reader

2008-01-29 Thread Stefan Behnel
Ricardo Aráoz wrote: What about : doc = moo bar99/bar /moo foo bar42/bar /foo 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(foo/bar) ... to read the value of: foo bar42/bar /foo Since

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 amounts from debits (any category) but not deposits. doc = ?xml

Re: REALLY simple xml reader

2008-01-29 Thread Ricardo Aráoz
What about : doc = moo bar99/bar /moo foo bar42/bar /foo 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

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: foo bar42/bar /foo Thanks Simon -- Linux user #458601 - http://counter.li.org

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 value of: foo bar42/bar /foo Since python2.5, the ElementTree

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.GetElement(foo/bar) ... to read the value of: foo

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 like this: xmlDoc