Robert Klemme
4/24/2008 9:10:00 PM
On 24.04.2008 02:17, Stedwick wrote:
> I have this line in my XML file that was created by REXML
>
> <episode name='03x08 - Future's End ~ 1' rating='100'>
>
> And I simply cannot access that element using REXML, at all, in any
> way, no matter what, as far as I can tell...
I am not sure what you mean, it works for me:
irb(main):003:0> s="<episode name='03x08 - Future's End ~ 1'
rating='100'/>"
=> "<episode name='03x08 - Future's End ~ 1' rating='100'/>"
irb(main):004:0> d = REXML::Document.new s
=> <UNDEFINED> ... </>
irb(main):005:0> d.elements
=> #<REXML::Elements:0x7fed20f4 @element=<UNDEFINED> ... </>>
irb(main):006:0> d.elements.each {|e| p e}
<episode name='03x08 - Future's End ~ 1' rating='100'/>
=> [<episode name='03x08 - Future's End ~ 1' rating='100'/>]
irb(main):007:0> d.elements.each {|e| p e.attributes}
{"name"=>name='03x08 - Future's End ~ 1', "rating"=>rating='100'}
=> [<episode name='03x08 - Future's End ~ 1' rating='100'/>]
irb(main):008:0> d.elements.each {|e| p e.attributes["name"]}
"03x08 - Future's End ~ 1"
=> [<episode name='03x08 - Future's End ~ 1' rating='100'/>]
irb(main):009:0> d.elements.each {|e| p e.attributes["rating"]}
"100"
=> [<episode name='03x08 - Future's End ~ 1' rating='100'/>]
> I have tried escaping the apostrophes, I have tried converting them to
> ', I have tried both directly accessing the element and using
> XPath, nothing works.
As I said, at least direct access works for me.
> Does anybody have any tricks for how to access elements that have
> attributes with apostrophes in their names? Thanks!
Kind regards
robert