in reply to Parsing XML output from `qstat`

... XML::Smart ...

I wouldn't :)

use XML::LibXML 1.70; ## for load_html/load_xml/location my $qstat = 'qstat.xml'; my $dom = XML::LibXML->new(qw/ recover 2 /)->load_xml( location => $qs +tat ); for my $job ( $dom->findnodes( q{ /job_info/queue_info/Queue-List + } ) ){ print $job->nodePath, "\n"; for my $slot ( $job->findnodes( q{ ./job_list/slots } ) ){ print $slot->nodePath, "\n"; print $slot, "\n"; print $slot->textContent, "\n"; } } __END__ /job_info/queue_info/Queue-List /job_info/queue_info/Queue-List/job_list/slots <slots>1</slots> 1

Re: parsing xml, xpather.pl/htmltreexpather.pl

Also , if you're going to post xml, make sure its well-formed first

Replies are listed 'Best First'.
Re^2: Parsing XML output from `qstat`
by Macslayer (Initiate) on May 05, 2014 at 18:04 UTC
    I've fixed the problem, and it didn't have to do with XML::Smart. After running your code and it working for the entire output of qstat, I investigated further as to why. LibXML requires the user to have the XML in a file before it can parse it, so I switched the $qstat variable in my original example to reading the output from a file. Once I did that, XML::Smart worked perfectly. Thanks for the code, though; I may have to switch to LibXML! It does get a bit messy compared to XML::Smart, though.

      so I switched the $qstat variable in my original example to reading the output from a file. Once I did that, XML::Smart worked perfectly

      Now that is a sign of quality :) like kcott I cannot reproduce that ... string or filename XML::Smart spits out 1

      It does get a bit messy compared to XML::Smart, though.

      What does that mean?

      DOM is the standard , used across all programming languages everywhere...

      If I'm chosing nonstandard I'm going with XML::Twig or XML::Rules

        Okay, I'll check out XML::Twig; looks cool! I did find the actual root of the problem, though: on the line where I get the output from qstat, I do:  $qstat = `qstat -u \* -ext -xml -s r -F`; That backslash in the command is getting escaped and not being sent to the operating system, so the command wasn't even outputting anything. *doh*