By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

Bug in Elementtree/Expat

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

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

P: n/a

<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

P: n/a
"""
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 discussion thread is closed

Replies have been disabled for this discussion.