You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by dao <da...@gmail.com> on 2010/05/17 16:02:50 UTC

adding a fragment of SVG to a document

hello, perhaps this is a pure trivial DOM question, sorry in that case:

I have a canvas with a loaded document (ALWAYS_DYNAMIC)



I want to add a piece of SVG document to the canvas' document. To do that, I
try to use the DomUtiliities Class.

String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Node foo = DOMUtilities.parseXML(text,
canvas.getSVGDocument(),canvas.getURI(), null, null,f);
final Element parent = canvas.getSVGDocument().getElementById("Components");
parent.appendChild(foo);
System.out.println("foo appended");

I want to add this piece of SVG (value of the text variable):
<text id="fooText" ...>FOO</text>

but then, the returned node is null (createDocument fails). I suppose <text>
is not enought, I have to specify it is SVG.

Then, I surrounded the text tag with a <!DOCTYPE..><svg> ... </svg> and it
works well. But when I look to my SVG document, it contains the SVG tag.
<svg...>
  <g id="Components">
    <svg ...>
      <text ...>
   </svg>
  </g>
  ...
</svg>

How can I have this:?
<svg...>
  <g id="Components">
      <text ...>
  </g>
  ...
</svg>

thank's

-- 
Dao Hodac

Re: adding a fragment of SVG to a document

Posted by dao <da...@gmail.com>.
OK, thank's

On Thu, May 20, 2010 at 11:40 AM, <th...@kodak.com> wrote:

> Hi Dao,
>
> dao <da...@gmail.com> wrote on 05/17/2010 10:02:50 AM:
>
> > adding a fragment of SVG to a document [...]
> > I have a canvas with a loaded document (ALWAYS_DYNAMIC)
>
> > I want to add this piece of SVG (value of the text variable):
> > <text id="fooText" ...>FOO</text>
> >
> > but then, the returned node is null (createDocument fails). I
> > suppose <text> is not enought, I have to specify it is SVG.
>
>         Correct.
>
> > Then, I surrounded the text tag with a <!DOCTYPE..><svg> ... </svg>
> > and it works well.
>
>         BTW you should only need the <svg>...</svg>.
>
> > But when I look to my SVG document, it contains
> > the SVG tag.
>
>         Well it was there in the input.
>
> > How can I have this:?
>
>         Use the Dom's methods to get the 'firstChild'
> of the returned document's root element, and append that.
>



-- 
Dao Hodac

Re: adding a fragment of SVG to a document

Posted by th...@kodak.com.
Hi Dao,

dao <da...@gmail.com> wrote on 05/17/2010 10:02:50 AM:

> adding a fragment of SVG to a document [...]
> I have a canvas with a loaded document (ALWAYS_DYNAMIC)

> I want to add this piece of SVG (value of the text variable):
> <text id="fooText" ...>FOO</text>
> 
> but then, the returned node is null (createDocument fails). I 
> suppose <text> is not enought, I have to specify it is SVG.

        Correct.

> Then, I surrounded the text tag with a <!DOCTYPE..><svg> ... </svg> 
> and it works well.

        BTW you should only need the <svg>...</svg>.

> But when I look to my SVG document, it contains 
> the SVG tag.

        Well it was there in the input.

> How can I have this:?

        Use the Dom's methods to get the 'firstChild' 
of the returned document's root element, and append that.