logo       

Problem with REXML: msg#01136

lang.ruby.general

Subject: Problem with REXML

Hi!

I think I have an problem understanding REXML.

let's say I have this XML file:

<?xml version="1.0" ?>
<INVENTORY>
<BOOK>
<TITLE>lala</TITLE>
<AUTHOR>hans</AUTHOR>
</BOOK>
<BOOK>
<TITLE>lele</TITLE>
<AUTHOR>hens</AUTHOR>
</BOOK>
</INVENTORY>

Now I want my application to get the author of the book called "lala".
In my perfect world something like that would work:

doc.each_element("BOOK") {|book| puts book.element("AUTHOR") if
"lala" == book.element("TITLE")}

or, even better:

@element = Element.new()
doc.each_element("BOOK") {|book| @element = book if
"lala" == book.element("TITLE")}


working with the documentation of REXML, it seems, that the usual way
to access a certein element is over its attributes, which is pretty
useless in my example.
And it seems impossible to get the parent of an element.

have I missed something?

regards,

Andreas.



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise