Neil Middleton
Neil Middleton

Reputation: 22238

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?

Upvotes: 1

Views: 262

Answers (2)

Chuck
Chuck

Reputation: 237060

You can just use current_node.children.

Upvotes: 1

Simone Carletti
Simone Carletti

Reputation: 176412

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.

Upvotes: 0

Related Questions