Perl HTML :: Element - dumping only descendants as HTML

I am having trouble trying to output the content of the mapped node that I am processing:

<div class="description">some text <br/>more text<br/></div>

      

I use HTML::TreeBuilder::XPath

node to search (there is only one div with this class):

my $description = $tree->findnodes('//div[@class="description"]')->[0];

      

It finds the node (returns as HTML::Element

I suppose) but $description->as_HTML

also includes the element itself - I just want everything contained inside the element to be HTML:

some text <br/>more text<br/>

      

I can obviously create a regex, but that seems like a mess and I'm sure I'm just missing a function somewhere to do this?

+3


source to share


2 answers


Try this:

my $description = $tree->findnodes('//div[@class="description"]/text()')->[0];

      



This is an Xpath trick.

0


source


Use ./node()

to retrieve all trays including text and items.



my $description = $tree->findnodes('//div[@class="description"]/node()');

      

0


source







All Articles