Bug in Elementtree/Expat

Discussion in 'Python' started by alainpoint@yahoo.fr, May 17, 2005.

  1. Guest

    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
     
    , May 17, 2005
    #1
    1. Advertising

  2. 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>
     
    Fredrik Lundh, May 17, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , May 17, 2005
    #3
  4. <> wrote in message news:...

    > 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.
     
    Richard Brodie, May 18, 2005
    #4
  5. Guest

    """
    > 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
     
    , May 20, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Madore
    Replies:
    1
    Views:
    543
    Richard Tobin
    Aug 28, 2003
  2. sharan
    Replies:
    1
    Views:
    739
    Pavel Lepin
    Oct 26, 2007
  3. limodou

    Element bug?(ElementTree)

    limodou, Dec 23, 2007, in forum: Python
    Replies:
    0
    Views:
    334
    limodou
    Dec 23, 2007
  4. Kee Nethery
    Replies:
    12
    Views:
    2,206
    Stefan Behnel
    Jun 27, 2009
  5. kj
    Replies:
    2
    Views:
    148
    Andreas Puerzer
    Feb 19, 2006
Loading...

Share This Page