Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: get text from node - XML::LibXML

by hippo (Bishop)
on Jul 20, 2018 at 09:49 UTC ( [id://1218875]=note: print w/replies, xml ) Need Help??


in reply to get text from node - XML::LibXML

Here is an SSCCE:

use strict; use warnings; use XML::LibXML; use Test::More tests => 1; my $in = '<seg><foo mid="0" mtype="seg"><g id="1">Need to export this +text</g></foo></seg>'; my $want = '<g id="1">Need to export this text</g>'; my $xml = XML::LibXML->load_xml (string => $in); my $have = $xml->getElementsByTagName ('g')->shift->toString; is ($have, $want);

Replies are listed 'Best First'.
Re^2: get text from node - XML::LibXML
by corfuitl (Sexton) on Jul 20, 2018 at 11:47 UTC

    Hi,

    Thank you for your help. I gave it a try and it works when it has tags. However, there are cases where the extracted text doesn't contain tags (i.e. <seg><foo mid="0" mtype="seg">Need to export this text</foo></seg>.

    i used this one my $mrktext = $mrk->getElementsByTagName ('*')->shift->toString;

    .

      What is your full code? What output do you get? What do you expect?

      Unless you tell us that, we can't figure out where you're going wrong.

      Here's the code for an example I created:

      use strict; my $str = q{<seg><foo mid="0" mtype="seg"><g id="1">Need to export thi +s text</g></foo></seg>}; my $xml = XML::LibXML->load_xml(string => $str); print $xml->getElementsByTagName("g")->shift->toString, "\n";

      The output is:

      <g id="1">Need to export this text</g>

      Which is exactly what I'd expect it to be.

      What is your full code? What output do you get? What do you expect?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-19 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found