Question about Nokogiri xpath

I am trying to parse an xml file using nokogiri. If any body has
experience with nokogiri. I request you to help.

Sample xml file.

It can be seen that Column element has two child elements. But when I
use

input = Nokogiri::XML(File.new(file))
input.xpath(’//table/column’).each do |column|
column.children.length
end

The result is 5.

While the element is at index 1, element
is at index 5. Does any one know why this is.

Thanks
venkat

Hi Venkat,

On Thu, Aug 27, 2009 at 06:49:41AM +0900, Venkat A. wrote:

    <onCreateDefault/>

The result is 5.

While the element is at index 1, element
is at index 5. Does any one know why this is.

Your XML contains whitespace nodes. The whitespace nodes are maintained
in the tree that Nokogiri produces. If you iterate over each node, you
can see this in action:

input.xpath(‘//table/column’).each do |column|
# Check each child for blankness
column.children.each { |child| puts child.blank? }
end

If you do not care to maintain whitespace nodes, you can tell the parser
to disable blank nodes like this:

input = Nokogiri::XML(File.new(file)) { |cfg| cfg.noblanks }

I hope that helps!

If you have more questions, I encourage you to join the nokogiri mailing
list which can be found here:

http://groups.google.com/group/nokogiri-talk

Thanks Aaron

   That helped. Good to hear back from the creator of Nokogiri 

himself.

Venkat