- From: Helder Magalhães <helder.magalhaes@gmail.com>
- Date: Sat, 23 Jan 2010 17:37:53 +0000
- To: Francis Hemsher <fhemsher@gmail.com>
- Cc: Jeff Schiller <codedread@gmail.com>, www-svg@w3.org
Hi Francis,
> elements and strings. What is needed is a seamless way to take the xml
> element string and plant it as an svg element in the SVG document.
Humm... Isn't that exactly what Jeff stated in the previous message? I
can only guess the function could be renamed to "xmlstring2dom" to
make it a little more clear. Or maybe I'm missing something... ;-)
> Similar to Adobe's parseXML() function.
BTW: Batik provides such functionality as well [1]. Maybe the code
snippet could be improved in order to account for this extension?
Something like the following (absolutely untested code!):
function xmlstring2dom(sXML) {
if(typeof(parseXML == "function"){
try{
return parseXML(sXML, document);
} catch(e){
throw new Error("Error while parsing XML");
}
}
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{
var out;
if($.browser.msie) out = (dXML.loadXML(sXML))?dXML:false;
else out = dXML.parseFromString(sXML, "text/xml");
return out;
}
catch(e){ throw new Error("Error parsing XML string"); };
}
Ah, and the dollar signs hint towards a jQuery or similar dependency
which needs to be addressed before this can be considered fully
generic. :-)
Cheers,
Helder
[1] http://xmlgraphics.apache.org/batik/status.html#ecmascript
Received on Saturday, 23 January 2010 17:38:42 UTC