From: William James Date: 2005-01-22T15:20:56+09:00 Subject: Re: Raw Elements trans. wrote: > Well, I just want to specify a tag and anything in that tag would be > left verbatim. That's all really. I'm tryng to find info on libxml > bindings (rather difficult to find it seems) though I have a feeling > that won't work either. > > Worse comes to worse I'll wipe out old trust Tagiter and see if that > will do. Otherwise I'll have to roll my own. Just what I need More > Work! > > Thanks Ari. Here's a micro xml-parser (posted via Google, so the indentation has been removed): # Produces array of nonmatching and matching # substrings. The size of the array will # always be an odd number. The first and the # last item will always be nonmatching. def shatter( s, re ) s.gsub( re, "\1"+'\&'+"\1" ).split("\1") end def get_attr( s ) h = Hash.new while s =~ /(\w+)="([^"]*)"/ h[$1] = $2 s = $' end h end def tag_name( s ) if ( s =~ /^<(\S+)(\s|>)/ ) $1 else nil end end s = '' $<.each_line {|x| s=s+x} all = shatter( s, /<[^>]*>/ ) all.each {|x| x.chomp! if x.size > 0 print x tname = tag_name(x) print " | " + tname if tname print "\n" attr = get_attr( x ) if attr.size > 0 attr.each_pair {|key,val| puts "....#{key}-->#{val}" } end end } With this input: The Frighteners A psychic private detective, who consorts with deceased souls, becomes engaged in a mystery as members of the town community begin dying mysteriously. M130Horror the output is: | ?xml .....encoding-->UTF-8 .....version-->1.0 | tv | programme .....stop-->20041218225000+1000 .....start-->20041218204000 +1000 .....channel-->Network TEN Brisbane | title The Frighteners | /title | sub-title/ | desc A psychic private detective, who consorts with deceased souls, becomes engaged in a mystery as members of the town community begin dying mysteriously. | /desc | rating .....system-->ABA | value M | /value | /rating | length .....units-->minutes 130 | /length | category Horror | /category | /programme