What I'm trying to do is pul the code block that contains the td with the class default. This works perfectly fine. But then I need to sort out the different parts of the code block. When I try to do this with the second xpath call what it does is each time it prints all the comheads in each of the blocks

def HeaderProcessor(doc)
doc.xpath("//td[@class='default']").each do |block|
puts block.xpath("//span[@class='comhead']").text
end
end

When I just print out block each block prints out once and contains the comment header and the comment. When I try to run the xpath it prints out EVERY comhead found in doc and seems to be ignoring the block variable.

Any ideas on how I can make this work? What am I miss understanding about xpath?

A few things don't make sense to me: 1. If I am using the block variable, how come it can access all the other spans in the other blocks. I'm using block as the new doc basically. 2. When I try your first example it gives me a bunch of empty lines and it nothing else. When I try your second example, it doesn't output anything. I've added a simplified version of the actual HTML to my original question. I hope that is helpful.
–
Noah ClarkSep 21 '11 at 19:31

@NoahClark: The first and second examples didn't work because you had extra elements inside your <td> that I didn't know about, I've updated it to account for the new structure. Your block is still attached to doc so it knows where the root is so //... starts again at doc; this may or may not be correct but that's what it is doing.
–
mu is too shortSep 21 '11 at 20:13