Bugs item #8370, was opened at 2007-02-01 13:04
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=8370&group_id=494
Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Doug Bryant (dougbryant)
>Assigned to: Charlie Savage (cfis)
Summary: The XML::Node::Set first() method behavior
Initial Comment:
With the 0.4 pre release, the following behavior is present:
If you find("//xpath_query") and the result is empty but still ask for the
first element, it will return to you an XML::Node::Set
The desired behavior should mimic the ruby array, which returns nil
See below.
irb(main):032:0> doc =
XML::Parser.string("<foo><bar><baz></baz></bar></foo>").parse
=> <?xml version="1.0"?>
<foo>
<bar>
<baz/>
</bar>
</foo>
irb(main):033:0> doc.find("//baz")
=> <baz/>
irb(main):034:0> doc.find("//woot")
=>
irb(main):035:0> doc.find("//baz").class.name
=> "XML::Node::Set"
irb(main):036:0> doc.find("//baz").first.class.name
=> "XML::Node"
irb(main):037:0> doc.find("//woot").class.name
=> "XML::Node::Set"
irb(main):038:0> doc.find("//woot").first.class.name
=> "XML::Node::Set"
irb(main):039:0>
The Ruby behavior...
irb(main):039:0> [].first
=> nil
----------------------------------------------------------------------
>Comment By: Charlie Savage (cfis)
Date: 2008-07-09 02:53
Message:
This is fixed.
----------------------------------------------------------------------
Comment By: Kuba Podgórski (kuba)
Date: 2007-07-25 08:05
Message:
What about version 0.3.8.4?
In line doc.find("//baz").first.class.name
i got error:
irb(main):020:0> doc.find("//baz").first.class.name
NoMethodError: undefined method `first' for #<XML::Node::Set:0xb7d0a134>
Thx.
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=1971&aid=8370&group_id=494
_______________________________________________
libxml-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/libxml-devel