title: How to automatically add attributes to specific XML elements (R or Perl or...)
body: <p>I am generating SVg files from inkscape and would like to edit them automatically to add some properties to selected element in the file. </p>
  
  <p>Let's say to original SVG looks like this</p>
  
  <pre><code>&lt;svg height="100" width="100"&gt;
  &lt;circle cx="50" cy="50" r="40" fill="red" id="red-circle"/&gt;
  &lt;circle cx="100" cy="50" r="40" fill="green" /&gt;
  &lt;/svg&gt; 
  </code></pre>
  
  <p>then I would like to find the elements having and <strong>id</strong> and add to these elements some other attributes such as the final xml looks like this</p>
  
  <pre><code>&lt;svg height="100" width="100"&gt;
  &lt;circle cx="50" cy="50" r="40" fill="red" id="red-circle" new-attribute="newvalue"/&gt;
  &lt;circle cx="100" cy="50" r="40" fill="green" /&gt;
  &lt;/svg&gt; 
  </code></pre>
  
  <p>I was wondering what would be the best was to automate this process (find element with tag id and add new attributes to them). I would need to do it on an important number of large SVG files, so automation is absolutely required.... I though about doing this in R or Perl, but I am open to any suggestions.</p>
  
  <p>PS: The overall structure of the SVG is likely to change between documents, so I can not rely on the structure of the document to parse it. The only clue I have is that some element have an id attribute</p>