W3C home > Mailing lists > Public > www-svg@w3.org > June 2002

Re: SVG --> HTML/TXT for searching and accessibility

From: Tobias Reif <tobiasreif@pinkjuice.com>
Date: Wed, 12 Jun 2002 10:40:43 +0200
Message-ID: <3D07090B.9060508@pinkjuice.com>
To: www-svg@w3.org
CC: Dean Jackson <dean@w3.org>

Dean Jackson wrote:

> Alternatively, you could write a program that
> ignores everything within angle brackets (bonus points to
> anyone who can do this in a program of 25 characters or
> less!)
> 
> If you have suggestions for improvement or if you do actually
> write a program to do the same thing, let me know and I'll
> link it from the page. I'll also include the smallest perl/python/ruby/etc
> script anyone comes up with to extract text from an SVG 
> file.


Although I agree with Dave's points, here's one more overly simplistic 
program:

#!/usr/local/bin/ruby

svg='<svg>
   <title>granny</title>
   <desc id="foo">my granny on the balkony</desc>
   <g>
     <text>2002</text>
   </g>
   <rect/>
</svg>'

ary =
  svg.gsub(/>\s+</,'><').
  scan(/<([^\s>]+)[^>]*?>([^<]+?)</)

ary.each do |element_name,text|
  puts element_name+': '+text
end

# prints:
=begin
title: granny
desc: my granny on the balkony
text: 2002
=end

Tobi


-- 
http://www.pinkjuice.com/
Received on Wednesday, 12 June 2002 04:39:56 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:22 GMT