Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Mojo::DOM doesn't include marked-up text in an element's text

by choroba (Cardinal)
on Apr 22, 2020 at 22:51 UTC ( [id://11115914]=note: print w/replies, xml ) Need Help??


in reply to Mojo::DOM doesn't include marked-up text in an element's text

It's a feature. XML::LibXML behaves similarly:
#!/usr/bin/perl use strict; use warnings; use feature qw{ say }; use XML::LibXML; my $xml = '<r><p>Paragraph one here.</p><p>Paragraph <b>two</b> here.< +/p></r>'; my $dom = 'XML::LibXML'->load_xml(string => $xml); print $dom->findvalue('/r/p[2]'); # Same as $dom->findnodes('/r/p[2]/ +/text()') # Paragraph two here. print $dom->findnodes('/r/p[2]'); # Same as map $_->toString, $dom->f +indnodes('/r/p[2]') # <p>Paragraph <b>two</b> here.</p> print $dom->findnodes('/r/p[2]/text()'); # Paragraph here

What do you mean by "complete text"?

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Mojo::DOM doesn't include marked-up text in an element's text
by marto (Cardinal) on Apr 23, 2020 at 11:10 UTC

    "What do you mean by "complete text"?"

    What anonymous said below, the method Cody Fendant should have used to get the combined text for all descending nodes is all_text, rather than text, so

    print $e->text,$/;

    becomes

    print $e->all_text,$/;

    Very handy, even for one liners/ojo use.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115914]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found