Hi everybody...

currently i'm trying to parse an xml file using perl but i got some error. i need to differentiate ELEMENT_NODE and TEXT_NODE, so that my program will only focus on the element_node. Here is the xml file;

<?xml version="1.0"?>
<buoy location="Rondo" position_east="10.82" position_north="34.67">
<data time="2006-03-30-T23:59:59+00:00" location="Rondo" parameter="Wind Speed" height="3.0" unit="m/s">1.234</data>
<data time="2006-03-30-T23:59:59+00:00" location="Rondo" parameter="Wind Speed" height="3.0" unit="m/s">1.234</data>
</buoy>


This is my current code:

use strict;
use XML::LibXML;
use Data:umper;

use constant TEXT_NODE => 3;
use constant ELEMENT_NODE => 1;

my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($filename);
my $root = $doc->getDocumentElement();
print "\nRoot element :", $root->nodeName, "\n";

my ($location, $timestamp, $parameter, $value);
while ($root->nodeName eq "buoy") {

$location = $root->getAttribute('location');
foreach my $child ($root->getChildNodes()) {
while ($child->nodeType == ELEMENT_NODE) {

if ( $child->nodeType == TEXT_NODE) {
next;
}

$value = $child->getFirstChild()->getData();
if ($child->nodeName eq "data") {

$timestamp = $child->getAttribute('time');
$parameter = $child->getAttribute('parameter');

# print $timestamp, "\n", $parameter , "\n";

} # end if


elsif ($child->nodeName ne "data") {
print "Error getting data from This file\n";
} # end elsif


$data{$location}->{$timestamp}->{$parameter} = $value;

} # end while

} # end foreach

} #end while

} # end process
print Dumper (\%data);


while compiling, i only get this:

[hayat@pc-hayat ~]$ perl checking_directory.pl

Root element :buoy



actually, i dont want to make it as hardcode..i prefer softcode..
how to parse this file correctly? Since i'm quite new in perl...could somebody please help me here ...


regards;
alnurhayat