W3C home > Mailing lists > Public > www-svg@w3.org > April 2009

Re: Trouble extending line element

From: G. Wade Johnson <gwadej@anomaly.org>
Date: Tue, 14 Apr 2009 06:57:19 -0500
To: "Ben Temperton" <benmpe@pml.ac.uk>
Cc: <www-svg@w3.org>
Message-ID: <20090414065719.0c8fac82@sovvan>
Instead of going the DTD route, you might want to try using a separate
namespace. That's supported by all of the viewers I'm aware of (and I'm
sure I'll be corrected if I forgot any<grin/>).

For example, see the changes I've made below.

On Tue, 14 Apr 2009 10:11:13 +0100
"Ben Temperton" <benmpe@pml.ac.uk> wrote:

> Hi there,
> I'm currently trying to extend the SVG DTD to allow me to have a new
> element in the <line> element like this:
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
> "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
> <!ENTITY % SVG.line.extra.content "| hit">
> <!ELEMENT hit (queryId, queryString) >
> <!ELEMENT queryId (#PCDATA)>
> <!ELEMENT queryString (#PCDATA)> ]>
> <svg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xmlns:xalan="http://xml.apache.org/xalan"
>      xmlns:xlink="http://www.w3.org/1999/xlink"
>      xmlns="http://www.w3.org/2000/svg"
>      style="fill-opacity:1; color-rendering:auto;
> color-interpolation:auto; stroke:black; text-rendering:auto;
> stroke-linecap:square; stroke-miterlimit:10; stroke-opacity:1;
> shape-rendering:auto; fill:black; stroke-dasharray:none;
> font-weight:normal; stroke-width:1; font-family:'Dialog';
> font-style:normal; stroke-linejoin:miter; font-size:12;
> stroke-dashoffset:0; image-rendering:auto;"
>      xsi:schemaLocation="http://www.w3.org/1999/xlink "
>      width="200"
>      height="100">
>     <text x="5" y="15" style="font-size:10; font-family:serif;
> stroke:none;" xml:space="preserve">Test matrix</text>
>     <rect x="0" y="30" width="10000" height="70" fill="black"
> stroke="black" stroke-width="1"/>
>     <g stroke="white">
>         <line y2="50" style="fill:none;" x1="100" x2="400" y1="50">
>         </line>
>     </g>
> </svg>
> but it's failing to accept the XML as a valid SVG when using Batik's
> Java JSVGCanvas object. However, Mozilla firefox can view the image
> fine.
> Can someone let me know what I'm doing wrong?

The big problem is that with the DTD method you are adding new elements
to the SVG namespace. When the viewer hits one, it has no idea how to
render the new element.

On the other hand, if the elements are in a different namespace, the
viewer can safely ignore them. It can assume that those elements are
meant for someone else to deal with.

I've used this tactic before with some success. In fact, you can even
access these elements through scripting, so they can contain
information you use to modify the SVG further later.

G. Wade
It is wise to remember that you are one of those who can be fooled some
of the time.                                       -- Laurence J. Peter
Received on Tuesday, 14 April 2009 11:58:04 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:17 UTC