473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Bug in Elementtree/Expat

Hello,

I use Elementtree to parse an elementary SVG file (in fact, it is one
of the examples in the "SVG essentials" book). More precisely, it is
the fig0201.svg file in the second chapter.
The contents of the file are as follows (i hope it will be rendered
correctly):
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="200" height="200">
<title>Default User Coordinates</title>
<desc>Shows a rectangle on a grid in default user coordinates</desc>
<image xlink:href="default_ruler.svg" x="0" y="0" width="200"
height="200"/>
<g transform="translate(40,40)">
<rect x="10" y="10" width="50" height="30"style="stroke: black; fill:
none;"/>
</g>
</svg>

The parsing fails in the following way:
Traceback (most recent call last):
File "C:\privatedata\myapp.py", line 60, in ?
root = ElementTree(file=infile).getroot()
File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line
554, in __init__
self.parse(file)
File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line
594, in parse
parser.feed(data)
File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line
1171, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: unbound prefix: line 6, column 1
The problem seems to lie with the xlink:href tag. If i remove the xlink
namespace, it then does not produce a traceback.

Thank you for helping
Alain

Jul 19 '05 #1
4 3701
al********@yahoo.fr wrote:
I use Elementtree to parse an elementary SVG file (in fact, it is one
of the examples in the "SVG essentials" book). More precisely, it is
the fig0201.svg file in the second chapter.
The contents of the file are as follows (i hope it will be rendered
correctly):
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="200" height="200">
<title>Default User Coordinates</title>
<desc>Shows a rectangle on a grid in default user coordinates</desc>
<image xlink:href="default_ruler.svg" x="0" y="0" width="200"
height="200"/>
<g transform="translate(40,40)">
<rect x="10" y="10" width="50" height="30"style="stroke: black; fill:
none;"/>
</g>
</svg>
xml.parsers.expat.ExpatError: unbound prefix: line 6, column 1 The problem seems to lie with the xlink:href tag. If i remove the xlink
namespace, it then does not produce a traceback.


so where in that file do you see an xlink declaration?

(elementtree doesn't fetch external DTD:s, so putting in the DTD file
doesn't really help).

adding

xmlns:xlink="http://www.w3.org/1999/xlink"

to the "svg" element should make the problem go away.

</F>

Jul 19 '05 #2

Fredrik Lundh wrote:

adding

xmlns:xlink="http://www.w3.org/1999/xlink"

to the "svg" element should make the problem go away.

Thanks for the tip. It indeed solves the problem.
Most examples in the book do not include such a declaration and yet are
properly rendered by Internet Explorer.
Is it mandatory and why is it that Expat crashes on it?

Alain

Jul 19 '05 #3

<al********@yahoo.fr> wrote in message news:11*********************@g47g2000cwa.googlegro ups.com...
Most examples in the book do not include such a declaration and yet are
properly rendered by Internet Explorer.
Is it mandatory and why is it that Expat crashes on it?


It's not mandatory but it's probably good practice to make the document
self-contained. The xlink prefix is defined in the DTD but Expat, as a
nonvalidating parser, won't fetch it.

Jul 19 '05 #4
"""
Most examples in the book do not include such a declaration and yet are properly rendered by Internet Explorer.
Is it mandatory and why is it that Expat crashes on it?


It's not mandatory but it's probably good practice to make the document
self-contained. The xlink prefix is defined in the DTD but Expat, as a
nonvalidating parser, won't fetch it.
"""

Important clarification:

The decision whether or not to read the external DTD subset is separate
from the decision whether or not to validate. Expat does not validate,
but it does read the external subset, if you tell it to. There are
other uses for reading the external subset, such as entity resolution.
And you can have validation constructs in the internal DTD subset (IOW
right in the XML source file itself), and expat will not do anything
with them because it does not validate.

This may seem a subtle distinction, but it lies behind a lot of user
confusion in practice. The XML WG really should have simplified such
matters (IIRC SGML compatability was a big obstruction to doing so).

--
Uche
http://uche.ogbuji.net

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stewart Midwinter | last post by:
I want to parse a file with ElementTree. My file has the following format: <!-- file population.xml --> <?xml version='1.0' encoding='utf-8'?> <population> <person><name="joe" sex="male"...
14
by: Erik Bethke | last post by:
Hello All, I am getting an error of not well-formed at the beginning of the Korean text in the second example. I am doing something wrong with how I am encoding my Korean? Do I need more of a...
1
by: Greg Wilson | last post by:
I'm trying to convert from minidom to ElementTree for handling XML, and am having trouble with entities in DTDs. My Python script looks like this: ...
3
by: mirandacascade | last post by:
Verion of Python: 2.4 O/S: Windows XP ElementTree resides in the c:\python24\lib\site-packages\elementtree\ folder When a string that does not contain well-formed XML is passed as an argument...
15
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
6
by: Sébastien Boisgérault | last post by:
I guess I am doing something wrong ... Any clue ? Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/elementtree/ElementTree.py", line 960,...
2
by: Sébastien Boisgérault | last post by:
Hi all, The unicode code points in the 0000-001F range -- except newline, tab, carriage return -- are not legal XML 1.0 characters. Attempts to serialize and deserialize such strings with...
1
by: Simon Pickles | last post by:
Hi, I've been using ElementTree for a few weeks without problem, with Stackless Python. Suddenly I have an error importing expat, in both application and console: simon@simon-desktop:~$...
2
by: =?ISO-8859-1?Q?J=2E_Pablo_Fern=E1ndez?= | last post by:
Hello, Is ElementTree supposed to load DTDs? I have some xmls heavy on entities and it fails this way: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) on linux2 Type "help", "copyright",...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.