Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Bug in Elementtree/Expat

Reply
Thread Tools

Bug in Elementtree/Expat

 
 
alainpoint@yahoo.fr
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      05-17-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

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

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

</F>



 
Reply With Quote
 
 
 
 
alainpoint@yahoo.fr
Guest
Posts: n/a
 
      05-17-2005

Fredrik Lundh wrote:
>
> adding
>
> xmlnslink="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

 
Reply With Quote
 
Richard Brodie
Guest
Posts: n/a
 
      05-18-2005

<(E-Mail Removed)> wrote in message news:(E-Mail Removed) 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.



 
Reply With Quote
 
uche.ogbuji@gmail.com
Guest
Posts: n/a
 
      05-20-2005
"""
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
ASP.NET Login control bug or SQL 2005 bug? RedEye ASP .Net 2 12-13-2005 10:57 AM
Re: BUG? OR NOT A BUG? John ASP .Net 2 09-21-2005 10:31 AM
Bug Parade Bug 4953793 Michel Joly de Lotbiniere Java 4 12-02-2003 05:05 AM
how to report bug to g++ ? got a bug and fixed up source code DarkSpy C++ 4 06-27-2003 09:05 AM



Advertisments