describeSensor.pl
Parse SOS DescribeSensor response.
describeSensor.pl
—
text/x-perl,
1Kb
File contents
#!/usr/bin/perl
use strict;
use XML::XPath;
use LWP::Simple;
# pass in a SOS DescribeSensor URL
# you may need to put single quotes around the url to escape it from the shell.
error("DescribeSensor URL is required.\nSample Usage: $0 'http://www.gomoos.org/cgi-bin/sos/oostethys_sos?request=DescribeSensor&sensorId=A01'\n")
if (@ARGV != 1);
my $xml_url = shift;
my $xml_url = 'http://www.gomoos.org/cgi-bin/sos/oostethys_sos?request=DescribeSensor&sensorId=A01';
my $xml = LWP::Simple::get($xml_url);
error("Could not fetch $xml_url.\n") if(!$xml);
my $xp = XML::XPath->new(xml => $xml);
# we reuse this.
my ($node, $nodeset);
my $sos_url;
my $i = 0;
# Perhaps in the future there will be more than one.
foreach my $node ($xp->find("//sml:SensorML/sml:System")->get_nodelist){
my $sensor_id = $node->getAttribute('id');
print "$sensor_id\n";
my $desc = $node->findvalue("sml:description/swe:Discussion");
print "$desc\n";
my $org = $node->findvalue("sml:contact/sml:ResponsibleParty/sml:organizationName");
print "$org\n";
my $type = $node->findvalue("sml:classification/sml:ClassifierList/sml:classifier/sml:Term");
print "$type\n";
foreach my $node2 ($node->find("sml:outputs/sml:OutputList/sml:output")->get_nodelist){
print "\t" . $node2->getAttribute('name') . "\n";
}
}
exit;
#######################################
sub error
{
my $msg = shift;
print $msg;
exit 1;
}

