Loading ...
Sorry, an error occurred while loading the content.

Adding a SVG doc from a String to a SVG document using javascript

Expand Messages
  • deimos1975
    Hi! My Javascript function receives a String as a parameter. This String is a svg tag with several nodes as children. I want to parse it into a SVG and add it
    Message 1 of 3 , Feb 8, 2013
    • 0 Attachment
      Hi! My Javascript function receives a String as a parameter. This String is a svg tag with several nodes as children. I want to parse it into a SVG and add it as a nodechildren to my SVG file is:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
      "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="100%" width="100%" onload="inicia(evt)" >

      <script type="text/ecmascript"><![CDATA[

      parent.pinta=pinta

      function inicia(event){
      SVGDocument = event.target.ownerDocument;
      }

      function pinta(strSVG){
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.loadXML(strSVG);
      var newNode=xmlDoc.documentElement;
      SVGDocument.getElementById('grafico1').appendChild(newNode);
      }
      ]]></script>
      <svg y="" width="" height="" id="grafico1"/>
      <svg y="500" width="" height="" id="grafico2"/>
      <g id="tip_Cuadro"/>
      <g id="tip_texto"/>
      </svg>

      Where strSVG="<g id='titulo'><text x='95' y='12'>Title </text></g>"

      But this returns a HIERARCHY_REQUEST_ERR (3) On: SVGDocument.getElementById('grafico1').appendChild(newNode);

      I think the proble is to parse String to a valid SVG node....
      This is on IE9.
      Thank you!
    • deimos1975
      Sorry newbie. Here is the file with the code: file
      Message 2 of 3 , Feb 8, 2013
      • 0 Attachment
        Sorry newbie.
        Here is the file with the code: file
        <http://f1.grp.yahoofs.com/v1/4AQVUbqxwVOZI2RfG2K-PyUp8aq1Uq1_in559fk3q6\
        P89zuSWSiRz2XLD-GDOAY55zUbNE-pjXiDVBVjnmkOhYKymIEeQvIF/stringTosvg>


        --- In svg-developers@yahoogroups.com, "deimos1975" wrote:
        >
        > Hi! My Javascript function receives a String as a parameter. This
        String is a svg tag with several nodes as children. I want to parse it
        into a SVG and add it as a nodechildren to my SVG file is:
        >
        >
        > "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
        >
        >
        >
        >
        >
        >
        >
        >
        >
        > Where strSVG=" Title "
        >
        > But this returns a HIERARCHY_REQUEST_ERR (3) On:
        SVGDocument.getElementById('grafico1').appendChild(newNode);
        >
        > I think the proble is to parse String to a valid SVG node....
        > This is on IE9.
        > Thank you!
        >



        [Non-text portions of this message have been removed]
      • Robert Longson
        Use DOMParser. See http://msdn.microsoft.com/en-gb/library/ie/ff975060%28v=vs.85%29.aspx for details. Best regards Robert. ...
        Message 3 of 3 , Feb 8, 2013
        • 0 Attachment
          Use DOMParser. See http://msdn.microsoft.com/en-gb/library/ie/ff975060%28v=vs.85%29.aspx for details.

          Best regards

          Robert.

          --- In svg-developers@yahoogroups.com, "deimos1975" wrote:
          >
          > Sorry newbie.
          > Here is the file with the code: file
          >
          P89zuSWSiRz2XLD-GDOAY55zUbNE-pjXiDVBVjnmkOhYKymIEeQvIF/stringTosvg>
          >
          >
          > --- In svg-developers@yahoogroups.com, "deimos1975" wrote:
          > >
          > > Hi! My Javascript function receives a String as a parameter. This
          > String is a svg tag with several nodes as children. I want to parse it
          > into a SVG and add it as a nodechildren to my SVG file is:
          > >
          > >
          > > "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
          > >
          > >
          > >
          > >
          > >
          > >
          > >
          > >
          > >
          > > Where strSVG=" Title "
          > >
          > > But this returns a HIERARCHY_REQUEST_ERR (3) On:
          > SVGDocument.getElementById('grafico1').appendChild(newNode);
          > >
          > > I think the proble is to parse String to a valid SVG node....
          > > This is on IE9.
          > > Thank you!
          > >
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.