G
Gerald Preissler
If I have an instance of REXML::Element, is there a convenient way to
get it's element name? I would have expected a get_name method for
Element or something like that, but according to the stdlib
documentation at http://www.ruby-doc.org/stdlib/ there is no such thing.
I found two ways that I do not like very much:
1. get the xpath to the element via Element.xpath and then extract the
actual name:
path = el.xpath
name = path.sub(/^\/(.+\/)*(\w*)(\[\d*\])?/ ,'\2')
I don't like this method since it feels wasteful.
2. Use instance_eval to get the value of Element::expanded_name:
irb(main):013:0> el.instance_eval('@expanded_name')
=> "import"
I don't like that either (I know I'm picky) since this means to use part
of the rexml implementation that is not part of the publicly documented
interface.
Is there an other way that I would like?
Thanks in advance for all advise and insights.
regards
Jerry
get it's element name? I would have expected a get_name method for
Element or something like that, but according to the stdlib
documentation at http://www.ruby-doc.org/stdlib/ there is no such thing.
I found two ways that I do not like very much:
1. get the xpath to the element via Element.xpath and then extract the
actual name:
path = el.xpath
name = path.sub(/^\/(.+\/)*(\w*)(\[\d*\])?/ ,'\2')
I don't like this method since it feels wasteful.
2. Use instance_eval to get the value of Element::expanded_name:
irb(main):013:0> el.instance_eval('@expanded_name')
=> "import"
I don't like that either (I know I'm picky) since this means to use part
of the rexml implementation that is not part of the publicly documented
interface.
Is there an other way that I would like?
Thanks in advance for all advise and insights.
regards
Jerry