REALLY simple xml reader
Steve Holden
steve at holdenweb.com
Thu Jan 31 07:41:57 EST 2008
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 recent call last):
>>>> File "<input>", line 1, in <module>
>>>> File "E:\Python25\lib\xml\etree\ElementTree.py", line 963, in XML
>>>> parser.feed(text)
>>>> File "E:\Python25\lib\xml\etree\ElementTree.py", line 1245, in feed
>>>> self._parser.Parse(data, 0)
>>>> ExpatError: XML or text declaration not at start of entity: line 2, column 0
>>> That's a problem in your XML not being XML. Has nothing to do with
>>> element-tree - as one sees from the error-message "ExpatError". If you
>>> show it to us, we might see why.
>>>
>> Sure,
>>
>> 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
newline in the string constant to have the parser ignore it:
doc = """\
<?xml version="1.0"?>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list