title: Parsing svg in python
body: <p>I have SVG and html file, which has couple of java script tags and I need to find all the script tags and insert a comment before the first script tag and than after the last script tag. I am trying to achieve it using Beautifulsoup. It worked well for HTML version but for SVG it is throwing error. </p>
  
  <pre><code> //for html version of file, working as expected
   soup = BeautifulSoup(data,selfClosingTags=['link','meta'])
   for num,tag in enumerate(soup.findAll('script')):
          if num==0:
              soup.head.insert(-1,startcomment)
          tag.extract()
          soup.head.insert(len(-1,tag)
          if num==len(soup.findAll('script'))-1:
              soup.head.insert(-1,endcomment)
  </code></pre>
  
  <p>but now when I try to achieve same for the svg as <code>soup = BeautifulSoup(data,"xml")</code> in the first line itself it throws exception.. svg is also xml? so I should be able to do it sameway</p>
  
  <p>Update - SVG format</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet href="../../../some.css" type="text/css"?&gt;
  &lt;svg id="mycontent" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"   xmlns:svg="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" focusable="true" onload="Jsfunction.load()"&gt;
  &lt;script xlink:href="../first.js" /&gt;
  &lt;script xlink:href="../second.js" /&gt;
  &lt;script xlink:href="../third.js" /&gt;
  &lt;/svg&gt;
  </code></pre>
  
  <p>should be changed to </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet href="../../../some.css" type="text/css"?&gt;
  &lt;svg id="mycontent" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"   xmlns:svg="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" focusable="true" onload="Jsfunction.load()"&gt;
  &lt;!-- some comment --&gt;
  &lt;script xlink:href="../first.js" /&gt;
  &lt;script xlink:href="../second.js" /&gt;
  &lt;script xlink:href="../third.js" /&gt;
  &lt;!-- end comment --&gt;
  &lt;/svg&gt;
  </code></pre>