title: Perl: parse SVG file
body: <p>I want to parse an SVG file in Perl, but I see advice NOT to use certain libraries (XML::Simple, XML::XPath) for different reasons. The thread below suggests XML::LibXML::XPathContext;</p>
  
  <p><a href="https://stackoverflow.com/questions/21677123/perl-xml-svg-parser-unable-to-findnodes">Perl XML/SVG Parser unable to findnodes</a></p>
  
  <p>Assuming I use XML::LibXML::XPathContext, I'm still not sure how to extract the nodes I'm interested in:
  1) Those with an "id" that contains "Drawing...", their size (path fill... d=".. etc) and text ("tspan")
  2) The "path" nodes (at the bottom of the SVG) which are NOT part of any "Drawing_" node and their location (d="...)</p>
  
  <pre><code>use XML::LibXML;
  use XML::LibXML::XPathContext;
  
  my $doc = XML::LibXML-&gt;load_xml( location =&gt; $file);
  my $xpc = XML::LibXML::XPathContext-&gt;new( $doc);
  $xpc-&gt;registerNs(x =&gt; 'http://www.w3.org/2000/svg');
  
  foreach my $drawing ($xpc-&gt;findnodes( ??? ) {
      print "Found drawing\n";
  }
  
  foreach my $path ($xpc-&gt;findnodes( ??? ) {
      print "Found path\n";
  }
  </code></pre>
  
  <p>My SVG:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;svg version="1.2"&gt;
   &lt;g visibility="visible" id="Master" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"&gt;
    &lt;rect fill="none" stroke="none" x="0" y="0" width="86360" height="55880"/&gt;
   &lt;/g&gt;
   &lt;g visibility="visible" id="Page1"&gt;
    &lt;g id="Drawing_1"&gt;
     &lt;path fill="rgb(255,211,32)" stroke="none" d="M 15350,3285 L 31988,3285 31988,4937 15350,4937 15350,3285 15350,3285 Z"/&gt;
     &lt;path fill="none" stroke="rgb(128,128,128)" stroke-width="102" stroke-linejoin="round" d="M 15350,3285 L 31988,3285 31988,4937 15350,4937 15350,3285 15350,3285 Z"/&gt;
     &lt;g fill="rgb(0,0,0)" stroke="none" font-family="Arial Narrow embedded" font-size="635" font-style="normal" font-weight="700"&gt;
      &lt;text x="19327" y="3967"&gt;
       &lt;tspan x="19327 19471 19788 19962"&gt;Info&lt;/tspan&gt;&lt;/text&gt;
      &lt;text fill="rgb(0,0,0)" stroke="none" x="17558" y="4699"&gt;
       &lt;tspan x="17558"&gt;I&lt;/tspan&gt;&lt;/text&gt;
     &lt;/g&gt;
    &lt;/g&gt;
    &lt;g id="Drawing_2"&gt;
     &lt;path fill="rgb(207,231,245)" stroke="none" d="M 8747,10525 L 4810,10525 4810,8239 12684,8239 12684,10525 8747,10525 Z"/&gt;
     &lt;path fill="none" stroke="rgb(128,128,128)" stroke-width="102" stroke-linejoin="round" d="M 8747,10525 L 4810,10525 4810,8239 12684,8239 12684,10525 8747,10525 Z"/&gt;
     &lt;g fill="rgb(0,0,0)" stroke="none" font-family="Arial Narrow embedded" font-size="635" font-style="normal" font-weight="700"&gt;
      &lt;text x="5547" y="8872"&gt;
       &lt;tspan x="5547 6030"&gt;OK&lt;/tspan&gt;&lt;/text&gt;
      &lt;text fill="rgb(0,0,0)" stroke="none" x="5215" y="9604"&gt;
       &lt;tspan x="5215 5359 5676 5850"&gt;Info&lt;/tspan&gt;&lt;/text&gt;
     &lt;/g&gt;
    &lt;/g&gt;
    ...
    &lt;g&gt;
     &lt;path fill="none" stroke="rgb(51,153,255)" id="Drawing_78_0" stroke-width="102" stroke-linejoin="round" d="M 47291,16367 C 47291,17129 48093,16793 48482,17017"/&gt;
     &lt;path fill="rgb(51,153,255)" stroke="none" id="Drawing_78_1" d="M 48688,17383 L 48598,16917 48337,17064 48688,17383 Z"/&gt;
    &lt;/g&gt;
    &lt;g&gt;
     &lt;path fill="none" stroke="rgb(51,153,255)" id="Drawing_79_0" stroke-width="102" stroke-linejoin="round" d="M 39417,4937 C 39417,14271 23887,8230 23425,16977"/&gt;
     &lt;path fill="rgb(51,153,255)" stroke="none" id="Drawing_79_1" d="M 23415,17383 L 23577,16937 23277,16929 23415,17383 Z"/&gt;
    &lt;/g&gt;
    ...
   &lt;/g&gt;
  &lt;/svg&gt;
  </code></pre>