简体   繁体   中英

Non greedy searches with Hpricot?

I'm using Hpricot for traversing an XML packet. For each node I'm on, I want to get a list of the immediate children . However when using

(current_node/:section)

I'm getting ALL descendant sections, not just the immediate children.

How can I get around this?

您可以只使用current_node.children

From the documentation :

If you're looking for a single element, the at method will return the first element matched by the expression. In this case, you'll get back the element itself rather than the Hpricot::Elements array.

Does the following works for you?

current_node.at(:section)

If you prefer, you can also use the xpath child operator .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM