Ping_Bee has asked for the wisdom of the Perl Monks concerning the following question:

I need to extract name field in the below XML file,
<GroupsResponse> <Status>Success</Status> <Group resourceId="183837" id="11797" name="Test" description="" l +ocation=""> <ResourcePrototype id="10001" name="Cave"/> <Resource id="101052" name="ABC"/> <Resource id="101082" name="DEF"/> <Resource id="101094" name="GHI"/> </Group> </GroupsResponse>
expected output is
ABC DEF GHI

Replies are listed 'Best First'.
Re: Extract XML data using xml :: simple
by choroba (Cardinal) on Sep 17, 2015 at 12:38 UTC
    XML::Simple warns against using itself in the documentation. Your task is easy in XML::XSH2, a wrapper around XML::LibXML:
    open file.xml ; echo //Resource/@name ;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Extract XML data using xml :: simple
by toolic (Bishop) on Sep 17, 2015 at 12:39 UTC
    Don't use XML::Simple because its author states:
    The use of this module in new code is discouraged.
    An alternate is XML::Twig
    use warnings; use strict; use XML::Twig; my $str = ' <GroupsResponse> <Status>Success</Status> <Group resourceId="183837" id="11797" name="Test" description="" l +ocation=""> <ResourcePrototype id="10001" name="Cave"/> <Resource id="101052" name="ABC"/> <Resource id="101082" name="DEF"/> <Resource id="101094" name="GHI"/> </Group> </GroupsResponse> '; my $t = XML::Twig->new( twig_handlers => { Resource => sub { print $_->att('name'), "\n"; +} }, ); $t->parse($str); __END__ ABC DEF GHI

      This XML:Twig module is not present in our environment..so can anyone help with XMl:SIMPLE

        What Perl code have you written already to accomplish your task using XML::Simple? Mostly, you will need to take special note of the ForceArray argument and ideally force every element in your XML into an array.