w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I extract an attribute/property in Perl using XML::Twig module?

This is one way to get 100. It uses the first_child method:

use warnings;
use strict;
use XML::Twig;

my $xml = <<XML;
    <to _Id="100">Share</to>
    <body>A simple text</body>

my $twig = XML::Twig->new(twig_handlers => { note => &getId

sub getId {
    my ($twig, $mod) = @_;
    my $to_id = $mod->first_child('to')->att('_Id');
    print "$to_id 

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.