W3C home > Mailing lists > Public > www-svg@w3.org > January 2010

Re: DOM APIs - XML to SVG parsing

From: Francis Hemsher <fhemsher@gmail.com>
Date: Sun, 24 Jan 2010 00:53:55 -0500
Message-ID: <c41bcc9d1001232153ha85b9a6j8073e45d29d2ee86@mail.gmail.com>
To: Jeff Schiller <codedread@gmail.com>, Helder Magalh„es <helder.magalhaes@gmail.com>, www-svg@w3.org
Thanks Jeff and Helder,
I can see what your doing and it works nicely. I'm sure you can
appreciate the advantage of the SVG DOM accomplishing this with two
simple requests, rather than each of us building our own utilities.

I would like to refine these two method suggestions [let's call them
svgString() and svgElem() ]:

var mySVGstring=mySVGelement.svgString()
var newSVGelement=mySVGdoc.svgElem(mySVGstring)

The mySVGstring is an xml string that can be replicated as an SVG
element  in any defined SVG document:

var newSVGelement1=mySVGdoc1.svgElem(mySVGstring)
var newSVGelement2=mySVGdoc2.svgElem(mySVGstring)
var newSVGelement3=mySVGdoc3.svgElem(mySVGstring)
...etc.
Append the elements where needed in the various documents.

The above also bypasses the need to work with Document Fragments as
required in Adobe's parseXML().

Regards,
Francis

P.S. Jeff, it would be helpful if you suggested one or more of your
nice utility functions in this thread.
Just change the Subject to:
 Re: DOM APIs - <your suggestion title here>
Write your suggestion
and start it by sending it to: www-svg@w3.org

On 1/23/10, Francis Hemsher <fhemsher@gmail.com> wrote:
> Hi Jeff,
> Your 7630+ lines of  code look lovely;)
> I think you may have given me a hint. I'm going to work with the
> importNode method for a bit, today or tomorrow. If it looks like it
> will do the job then I'll post it on the list.
> Thanks,
> Francis
>
> On 1/23/10, Jeff Schiller <codedread@gmail.com> wrote:
>> Perhaps I'm not understanding you, but that's exactly what the
>> text2xml function does:  takes a string and returns a XML DOM ready to
>> be inserted.  Then you import the node into your document, then you
>> would use the standard DOM methods (insertNode, appendChild, etc) to
>> put it into your DOM.
>>
>> We have an example from SVG-edit at
>> http://code.google.com/p/svg-edit/source/browse/trunk/editor/svgcanvas.js#5002
>> (ignore the sanitizeSvg() call for now):
>>
>> // convert string into XML document
>> var newDoc = Utils.text2xml(xmlString);
>> ...
>> svgroot.appendChild(svgdoc.importNode(newDoc.documentElement, true));
>>
>> In this case, we have nested <svg> elements and svgroot points at the
>> outer <svg> but it could really be any HTML element too.
>>
>> Jeff
>>
>
Received on Sunday, 24 January 2010 05:54:27 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:44 GMT