James Gray
2/12/2006 5:14:00 PM
On Feb 12, 2006, at 11:05 AM, David Vallner wrote:
> Dna Nedela 12 Február 2006 17:18 Zdebel napísal:
>> Helo !
>> I've started to learn ruby and I'm amazed with it. Now I have a
>> problem
>> that I can't solve. If I have a string like this:
>> "<lyrics artist=XXX album=XXX title=XXX> Lalalalala </lyrics>" how
>> can I
>> cut the " artist=XXX album=XXX title=XXX" part, so it would look
>> like:
>> "<lyrcis> Lalalalala </lyrics>" Could you please help me ?
>
> The very geeky, and most probably least error-prone way would be
> whacking the
> string with a DOM parser, clearing the attributes, and then
> printing it out
> again. Unfortunately, I haven't been doing any DOM manipulation in
> Ruby, so I
> can't provide code.
The following is how you do it for valid XML, but the posted example
wasn't quite:
#!/usr/local/bin/ruby -w
require "rexml/document"
doc = "<lyrics artist='XXX' album='XXX' title='XXX'> Lalalalala </
lyrics>"
xml = REXML::Document.new(doc)
xml.root.attributes.clear
xml.write
puts
__END__
James Edward Gray II