Re: DOM APIs - XML to SVG parsing

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 UTC