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

Re: [svg-developers] Extracting common shapes from SVG documents

Expand Messages
  • ddailey
    Sujesh wrote ... I am working on an application , which uses SVG extensively as icons as well as background images . We are planning to provide an option for
    Message 1 of 4 , Jan 4, 2007
    • 0 Attachment
      Sujesh wrote
      -------------
      I am working on an application , which uses SVG extensively as icons as well as background images . We are planning to provide an option for mass editing of the icons.

      Is there any way i can extract common elements ( circles,rects.. etc ) from svg document?
      -----------------

      I don't know where this application is likely to run, but within the svg document itself you can use javascript to do much of the work sort of as follows:

      function multitag(O){
      var Shapes=new Array("rect","circle","path","ellipse")
      Shapelist=new Object
      for (i in Shapes){
      Shapelist[Shapes[i]]=O.getElementsByTagNameNS(xmlns,Shapes[i])
      for (j=0;j<Shapelist[Shapes[i]].length;j++){
      alert(Shapes[i]+" "+j+":"+Shapelist[Shapes[i]].item(j).nodeName)
      }
      }
      return Shapelist
      }

      The inner loop with the alerts is in there just to show step-by-step results.
      Basically this function can be invoked with a call like Stuff=multitag(SVGRoot)
      and then stuff will be an Object (sort of like an associative array), consisting of
      a collection of nodeLists organized by and indexed by node type ("rect","circle","path","ellipse").
      It can be accessed just as it is in the inner loop.

      Basically, the getElementsByTagNameNS method does all the work.

      Such code works for me in IE/ASV, Opera 9 and FF1.5.

      hope this makes sense,
      David


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.