in reply to XML parsing

So, to pull together the responses so far:
use XML::Simple; .. my @outputInfo = qx[$cmd]; # Discard that pesky first line, without needing to know # what the line ending chars are shift @outputInfo; # Join array to make a single string, with line endings # being turned into line endings (but not necessarily # exactly the same line endings as the command may have # used, depending on your OS, and/or the internals of the # command) my $ref = XMLin(join("\n", @outputInfo));

Replies are listed 'Best First'.
Re^2: XML parsing
by raju_400 (Novice) on Sep 22, 2008 at 05:43 UTC
    Thanks to all of you. I really like the solution of putting the cmd output to a scalar variable and also to an array after converting it by join.

    I carefully analysed the output of the cmd that contains as follows:

    first line: 'Starting webservices call'

    second line: blank

    third line: <?xml version="1.0"?>

    followed by the entire xml doc.

    I wonder how much would it be reliable to discard the first two lines, if this changes in future. Can I use .. and ... to extract between "<?xml version" and the last tag. Need some expert advice considering the reliability.

    Many thanks

    Sudip

      use XML::Simple; .. my $outputInfo = qx[$cmd]; $outputInfo =~ s/^.*?(?=<\?xml)//s; my $ref = XMLin($outputInfo));
        Please let me know what the regex is doing in the example given. While trying this I got the following:

        not well-formed (invalid token) at line 624, column 71, byte 30538 at c:/perl/lib/XML/Parser.pm line 187

        regards

        Sudip