my $xpath = '//div[@class="ccc"]/node()';
The way I understand that expression is "match any node of any kind that is a direct child of any <div> elements with a class attribute equal to ccc." If I remove all the whitespace from the XML, the matching <div> has three children: <img src="">, <h2>Hello</h2>, and <div class='s'>. And since node() matches any kind of nodes, including text nodes, that's what it's matching when you put the whitespace back in. You can see all of this in action if you put print "[[",$superCat->as_XML,"]]\n"; as the first thing in your loop. In other words, your XPath is behaving correctly. If you only want to match the <div class="ccc">, change the expression to //div[@class="ccc"].
(Also note that your XML is not valid, the <img> tag isn't closed.)
In reply to Re: HTML::TreeBuilder::LibXML creates multiple copies of the same result
by haukex
in thread HTML::TreeBuilder::LibXML creates multiple copies of the same result
by password
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |