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 Tracey Zellmann <tr...@comcast.net> on 2006/02/07 01:48:50 UTC

Making a copy of an SVG Document in memory

I want to make deep copies of an SVG document that has been read into memory.What is an efficient idiom for doing this - rather than reading the image in repeatedly from file? My application has several sets of data. Each set will be mapped onto the same SVG image and then printed out in a PDF report.

Re: Making a copy of an SVG Document in memory

Posted by Tracey Zellmann <tr...@comcast.net>.
Thank you very much! That was exactly what I was looking for. 


----- Original Message ----- 
From: "Cameron McCormack" <ca...@aka.mcc.id.au>
To: <ba...@xmlgraphics.apache.org>
Sent: Monday, February 06, 2006 7:56 PM
Subject: Re: Making a copy of an SVG Document in memory


> Hi Tracey.
> 
> Tracey Zellmann:
>> I want to make deep copies of an SVG document that has been read into
>> memory.What is an efficient idiom for doing this - rather than reading
>> the image in repeatedly from file? My application has several sets of
>> data. Each set will be mapped onto the same SVG image and then printed
>> out in a PDF report.
> 
> If you want to make copies of the document so you can change each one,
> you can use create a new document and then use Node.importNode to copy
> the content across (untested):
> 
>  Document doc = ...;   // your original document
>  DOMImplementation impl = doc.getDOMImplementation();
>  Document doc2;        // your new document
>  doc2 = impl.createDocument("http://www.w3.org/2000/svg", "svg", null);
>  doc2.replaceChild(doc2.importNode(doc.getDocumentElement(), true),
>                    doc2.getDocumentElement());
> 
> -- 
> Cameron McCormack ICQ: 26955922
> cam (at) mcc.id.au MSN: cam (at) mcc.id.au
> http://mcc.id.au/ JBR: heycam (at) jabber.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Making a copy of an SVG Document in memory

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Hi Tracey.

Tracey Zellmann:
> I want to make deep copies of an SVG document that has been read into
> memory.What is an efficient idiom for doing this - rather than reading
> the image in repeatedly from file? My application has several sets of
> data. Each set will be mapped onto the same SVG image and then printed
> out in a PDF report.

If you want to make copies of the document so you can change each one,
you can use create a new document and then use Node.importNode to copy
the content across (untested):

  Document doc = ...;   // your original document
  DOMImplementation impl = doc.getDOMImplementation();
  Document doc2;        // your new document
  doc2 = impl.createDocument("http://www.w3.org/2000/svg", "svg", null);
  doc2.replaceChild(doc2.importNode(doc.getDocumentElement(), true),
                    doc2.getDocumentElement());

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org