in reply to extracting attribute values which might have multiple occurences from xml file

Using XML::XSH2:
open test.xml ; for /httpsRoutes/httpsRoute echo @hostname (key) @tier | cat > out.txt
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: extracting attribute values which might have multiple occurences from xml file
  • Download Code

Replies are listed 'Best First'.
Re^2: extracting attribute values which might have multiple occurences from xml file
by perlDevsWorld (Novice) on Jan 30, 2015 at 21:49 UTC
    @choroba: Thanks so much for your response!. Looks interesting wrt xpath look a like. But running into below errors ( modified a little)
    #! perl -w use warnings; use strict; use XML::XSH2; my $tempVal = XML::XSH2->new( twig_handlers => { /httpsRoutes/httpsRou +te } ); $tempVal->parsefile("c:\\location\\test.xml"); for ($tempVal) { echo @hostname (key) @tier | cat > out.txt; }
    errors:

    C:\Strawberry\perl\bin>perl "C:\location\xmlRead_2.pl" Array found where operator expected at C:\location\xmlRead_2.pl line 10, at end of line (Missing operator before ?) Array found where operator expected at C:\location\xmlRead_2.pl line 10, at end of line (Missing operator before ?) Unknown regexp modifier "/h" at C:\location\xmlRead_2.pl line 6, at end of line Unknown regexp modifier "/t" at C:\location\xmlRead_2.pl line 6, at end of line Unknown regexp modifier "/t" at C:\location\xmlRead_2.pl line 6, at end of line Unknown regexp modifier "/R" at C:\location\xmlRead_2.pl line 6, at end of line Unknown regexp modifier "/t" at C:\location\xmlRead_2.pl line 6, at end of line Unknown regexp modifier "/e" at C:\location\xmlRead_2.pl line 6, at end of line syntax error at C:\location\xmlRead_2.pl line 10, near "echo @hostname " Global symbol "@hostname" requires explicit package name at C:\location\xmlRead_2.pl line 10. Global symbol "@tier" requires explicit package name at C:\location\xmlRead_2.pl line 10. Execution of C:\location\xmlRead_2.pl aborted due to compilation errors.

      You are mixing XML::Twig with XML::XSH2.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        @Choroba: Thanks so much for the help!. Its working now.
        @choroba: Apologies still trying to catch up with perl.
        #! perl -w use warnings; use strict; use XML::XSH2; open "C:\\location\\test.xml" ; for /httpsRoutes/httpsRoute echo @hostname (key) @tier | cat > out.txt

        Errors I'm getting:

        C:\Strawberry\perl\bin>perl "C:\location\xmlRead_3.pl Array found where operator expected at C:\location\xmlRead_3.pl line 8 +, at end of line (Missing operator before ?) Array found where operator expected at C:\location\xmlRead_3.pl line 8 +, at end of line (Missing operator before ?) Unknown regexp modifier "/h" at C:\location\xmlRead_3.pl line 7, at en +d of line Unknown regexp modifier "/t" at C:\location\xmlRead_3.pl line 7, at en +d of line Unknown regexp modifier "/t" at C:\location\xmlRead_3.pl line 7, at en +d of line Unknown regexp modifier "/R" at C:\location\xmlRead_3.pl line 7, at en +d of line Unknown regexp modifier "/t" at C:\location\xmlRead_3.pl line 7, at en +d of line Unknown regexp modifier "/e" at C:\location\xmlRead_3.pl line 7, at en +d of line syntax error at C:\location\xmlRead_3.pl line 7, near "for /httpsRoute +s/httpsRoute" Global symbol "@hostname" requires explicit package name at C:\locatio +n\xmlRead_3.pl line 8. Global symbol "@tier" requires explicit package name at C:\location\xm +lRead_3.pl line 8. Execution of C:\location\xmlRead_3.pl aborted due to compilation error +s.