tag:www.rhnh.net,2008:/svgSvg - Xavier Shay's Blog2007-08-15T07:29:57ZEnkiXavier Shaynotreal@rhnh.nettag:www.rhnh.net,2008:Post/1292007-07-01T07:29:00Z2007-08-15T07:29:57ZPractical Hpricot: SVG<p>Inkscape does a pretty good job of creating plain <span class="caps">SVG</span> files, but they could be nicer. A particular file I was working on had many path elements, all with the same style attribute that I wanted to move into a parent tag (or external style or whatever). What better way to strip them out than Hpricot?</p><table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span class="s"><span class="dl">'</span><span class="k">hpricot</span><span class="dl">'</span></span><tt>
</tt><tt>
</tt>doc = open(<span class="pc">ARGV</span>[<span class="i">0</span>]) { |f| <span class="co">Hpricot</span>.XML(f) }<tt>
</tt><tt>
</tt>(doc/<span class="sy">:path</span>).each <span class="r">do</span> |path|<tt>
</tt> [<span class="sy">:id</span>, <span class="sy">:style</span>].each <span class="r">do</span> |attr| <tt>
</tt> path.remove_attribute(attr)<tt>
</tt> <span class="r">end</span><tt>
</tt><span class="r">end</span><tt>
</tt><tt>
</tt>puts doc<tt>
</tt></pre></td>
</tr></table>
<p>And you get the benefit of prettier formatting!</p>