- From: Jeff Schiller <codedread@gmail.com>
- Date: Sat, 23 Jan 2010 10:53:16 -0600
- To: Francis Hemsher <fhemsher@gmail.com>
- Cc: www-svg@w3.org
Hi Francis,
You should look into the DOMParser interface, which is supported on
every modern browser (that excludes IE):
* http://www.w3schools.com/Dom/dom_parser.asp
* https://developer.mozilla.org/en/Parsing_and_serializing_XML
I think the DOMParser interface is defined here:
http://www.w3.org/TR/2003/WD-DOM-Level-3-LS-20030619/load-save.html#LS-DOMParser
but I don't see a parseFromString() function. Does anyone have any
idea if/where this has been standardized. If not, why not? I'm not
clear on the situation, but the following function works fine for me:
function text2xml(sXML) {
var out;
try{
var dXML = ($.browser.msie)?new
ActiveXObject("Microsoft.XMLDOM"):new DOMParser();
dXML.async = false;
} catch(e){
throw new Error("XML Parser could not be instantiated");
};
try{
if($.browser.msie) out = (dXML.loadXML(sXML))?dXML:false;
else out = dXML.parseFromString(sXML, "text/xml");
}
catch(e){ throw new Error("Error parsing XML string"); };
return out;
}
Regards,
Jeff
On Sat, Jan 23, 2010 at 9:56 AM, Francis Hemsher <fhemsher@gmail.com> wrote:
> There are two things I do lots of:
> 1.Create SVG elements from XML files.
> 2.Transfer SVG elements between documents.
>
> Typically I use the Adobe SVG Viewer printNode() and parseXML() functions.
> as follows:
> 1. Create an SVG elem from XML String:
> var docFrag=parseXML(xmlString,DocSVG)
> var svgElem=docFrag.firstChild
> mySVG.appendChild(svgElem)
>
> 2.Copy an SVG element from Doc1SVG to Doc2SVG:
> var svgString=Doc1.printNode(Doc1SVGelement)
> var docFrag=parseXML(svgString,Doc2SVG) //---Doc2 parseXML---
> var svgElem=docFrag.firstChild
> mySVG2.appendChild(svgElem)
>
> We certainly need some form of these methods to be included.
>
> Back in 2002, Antoine Quint wrote:
> "...the SVG Working Group has received strong feedback from the SVG
> community to make these methods available in a W3C standard. The Group
> is looking into that and SVG 1.2 looks like a great candidate to have
> those two methods defined (probably as convenient shorthands for DOM
> Level 3 Load and Save methods)."
>
> see:
> http://www.xml.com/pub/a/2002/07/03/adobesvg.html
>
> I've looked around the current and proposed W3C Recommendations and
> can't find reference to this. Have these features been addressed under
> a subject heading that I have missed?
>
> Thanks for any feedback,
> Francis
>
>
Received on Saturday, 23 January 2010 16:53:49 UTC