http://qs321.pair.com?node_id=1218892


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

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;

.

Replies are listed 'Best First'.
Re^3: get text from node - XML::LibXML
by tobyink (Canon) on Jul 20, 2018 at 12:53 UTC

    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?