473,574 Members | 3,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Defaul t User Coordinates</title>
<desc>Shows a rectangle on a grid in default user coordinates</desc>
<image xlink:href="def ault_ruler.svg" x="0" y="0" width="200"
height="200"/>
<g transform="tran slate(40,40)">
<rect x="10" y="10" width="50" height="30"styl e="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(fil e=infile).getro ot()
File "c:\python23\li b\site-packages\elemen ttree\ElementTr ee.py", line
554, in __init__
self.parse(file )
File "c:\python23\li b\site-packages\elemen ttree\ElementTr ee.py", line
594, in parse
parser.feed(dat a)
File "c:\python23\li b\site-packages\elemen ttree\ElementTr ee.py", line
1171, in feed
self._parser.Pa rse(data, 0)
xml.parsers.exp at.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 3723
al********@yaho o.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>Defaul t User Coordinates</title>
<desc>Shows a rectangle on a grid in default user coordinates</desc>
<image xlink:href="def ault_ruler.svg" x="0" y="0" width="200"
height="200"/>
<g transform="tran slate(40,40)">
<rect x="10" y="10" width="50" height="30"styl e="stroke: black; fill:
none;"/>
</g>
</svg>
xml.parsers.exp at.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="ht tp://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="ht tp://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********@yah oo.fr> wrote in message news:11******** *************@g 47g2000cwa.goog legroups.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
3257
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" age="49"></person> <person><name="hilda" sex="female" age="33"></person> <person><name="bartholomew" sex="male" age="17"> </person> </population>
14
7477
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 wrapper about it than simple quotes? Is there some sort of XML syntax for indicating a Unicode string, or does the Elementree library just not...
1
3079
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: ---------------------------------------------------------------------- #!/usr/bin/env python import sys, os from elementtree import ElementTree
3
3948
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 to the XML() method in ElementTree.py, an ExpatError exception is raised. I can trap the exception with a try/except where the except does not...
15
5407
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 encodings, so I'm sure I'm just screwing something simple up. Can anyone help me? Here's the interactive session. Sorry it's a little verbose, but...
6
2617
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, in XML parser.feed(text) File "/usr/lib/python2.4/site-packages/elementtree/ElementTree.py", line 1242, in feed self._parser.Parse(data, 0)
2
1662
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 ElementTree will fail: '<root char="\x00" />'
1
2079
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:~$ python Python 2.5.2a0 Stackless 3.1b3 060516 (release25-maint:60694M, Feb 9 2008, 13:21:41)
2
3632
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", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in <module>
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7815
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8098
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2243
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.