2012-11-02 102 views
2
#!/usr/bin/perl 

use strict; 
use warnings FATAL => 'all'; 
use 5.010; 

use XML::Twig; 

sub get_xml_from_data { 
    my @lines = <DATA>; 
    my $xml = join "", @lines; 

    return $xml; 
} 

sub main { 
    my $xml = get_xml_from_data(); 

    my $xt = XML::Twig->new(); 
    $xt->parse($xml); 
    my $root= $xt->root; 

    # output 1 
    say $root->first_child('element')->sprint; 
    # It will print: 
    # 
    # <element> 
    #   Some content with <b>some</b> <i><b>other</b></i> tags. 
    #  </element> 

    # output 2 
    say $root->first_child('element')->text; 
    # It will print: 
    # 
    #  Some content with some other tags. 


    # But I need the output: 
    # 
    #   Some content with <b>some</b> <i><b>other</b></i> tags. 

} 

main(); 

__DATA__ 
<root> 
    <element> 
     Some content with <b>some</b> <i><b>other</b></i> tags. 
    </element> 
</root> 

回答

2

您正在查找的方法是inner_xml

+0

谢谢!这是我所需要的! =) – bessarabov

相关问题