Question

As an example, I have a Perl XML::Twig object $xmlDef, which contains the following:

<ROOT>
  <CHILD>
  </CHILD>
</ROOT>

It's generated with the following code:

    my $parser = XML::Twig->new(
            twig_handlers => {
                ROOT => sub { $xmlDef = $_ }
            },
            pretty_print  => 'indented'
    );
    $parser->parse($xmlStr);

When I view $xmlDef using $xmlDef->print, its contents get properly output to console. When I do print $xmlDef->text, nothing gets output. What am I doing wrong by using ->text?

Was it helpful?

Solution

The text method returns all the text content of the given element. Try adding some text to your XML:

<ROOT>
  <CHILD>
    This will be printed.
  </CHILD>
</ROOT>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top