in reply to Parsing XML output from `qstat`

G'day Ben,

Welcome to the monastery.

Short answer: I'm unable to reproduce your problem.

Longer answer:

I set up $qstat as a here-doc. I changed '... ?revision=1.11"' to 'revision="1.11"' and removed the other elision. Check that your original data (prior to replacing parts with '...') was actually valid XML.

Other than that, I used your code as written. The output was a lone "1" character as was expected from "<slots>1</slots>".

You actually don't need all those '->'s. I tried with the following code and got the same result.

for ($xml->{job_info}{queue_info}{'Queue-List'}('@')) { print $_->{job_list}{slots}; }

I'm not a user of XML::Smart. I had to install this module, so I used the latest 1.79 version. Check that you're also using this or upgrade. Also check for any problems with your OS or Perl version (I'm using 5.18.1 on darwin-thread-multi-2level).

Here's the actual code and data I used for my tests (in the spoiler):

#!/usr/bin/env perl -l use strict; use warnings; use XML::Smart; my $qstat = <<'EOX'; <?xml version='1.0'?> <job_info revision="1.11"> <queue_info> <Queue-List> <name>long_zeta@zeta09.local</name> <qtype>BIP</qtype> <slots_used>1</slots_used> <slots_resv>0</slots_resv> <slots_total>8</slots_total> <arch>lx26-amd64</arch> <resource name="arch" type="hl">lx26-amd64</resource> <resource name="num_proc" type="hl">8</resource> <job_list state="running"> <JB_job_number>642412</JB_job_number> <JAT_prio>5.00248</JAT_prio> <JAT_ntix>0.00002</JAT_ntix> <JB_name>U6s53097</JB_name> <JB_owner>npatel37</JB_owner> <JB_project>correlat</JB_project> <JB_department>defaultdepartment</JB_department> <state>r</state> <cpu_usage>224919.00000</cpu_usage> <mem_usage>15753.53518</mem_usage> <io_usage>0.32690</io_usage> <tickets>0</tickets> <JB_override_tickets>0</JB_override_tickets> <JB_jobshare>0</JB_jobshare> <otickets>0</otickets> <ftickets>0</ftickets> <stickets>0</stickets> <JAT_share>0.00002</JAT_share> <slots>1</slots> </job_list> </Queue-List> </queue_info> </job_info> EOX my $xml = XML::Smart->new($qstat); for ($xml->{job_info}->{queue_info}->{'Queue-List'}('@')) { print $_->{job_list}->{slots}; } #for ($xml->{job_info}{queue_info}{'Queue-List'}('@')) { # print $_->{job_list}{slots}; #}

-- Ken

Replies are listed 'Best First'.
Re^2: Parsing XML output from `qstat`
by Macslayer (Initiate) on May 05, 2014 at 18:05 UTC
    Thanks for the code! I've fixed it, which I describe in a post later on, finally using XML::Smart correctly.