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

Re: DOM APIs - XML to SVG parsing

From: Helder Magalh„es <helder.magalhaes@gmail.com>
Date: Sat, 23 Jan 2010 17:37:53 +0000
Message-ID: <2a1ddf8a1001230937q23dd0da5jf7c8e5a8f68ad06d@mail.gmail.com>
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"){
      return parseXML(sXML, document);
    } catch(e){
     throw new Error("Error while parsing XML");
     var dXML = ($.browser.msie)?new
ActiveXObject("Microsoft.XMLDOM"):new DOMParser();
     dXML.async = false;
  } catch(e){
     throw new Error("XML Parser could not be instantiated");
     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. :-)


[1] http://xmlgraphics.apache.org/batik/status.html#ecmascript
Received on Saturday, 23 January 2010 17:38:42 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:54:25 UTC