XML::DOM Query

B

-Brad-

Hi all, Im using the XML::DOM module to process an xml document but having a
few problems.
Im trying to loop though all the node attributes and retreive their values.
But having a few promlems.

The Perl code I have so far is

foreach my $child ($root->getChildNodes()) {

if ($child->getNodeType == TEXT_NODE){

#print "Text: ", $child->getData();
print "--------\n";

} elsif ($child->getNodeType == ELEMENT_NODE) {

print $child->getNodeName(), " = ",
$child->getFirstChild()->getData(), "\n";

$attribs = $child->getAttributes();

while ( my ($key, $value) = each(%$attribs) ) {
print "$key => $value\n";
# HERE I WOULD LIKE TO PRINT THE NAME AND VALUE OF
THE ATTRIBUTES
}

#$att = $attribs->getNamedItem("LetterHasDate");
#print " Attribute = " , $att->getValue() , "\n";
#print " ALSO = " ,
$child->getAttributes()->getNamedItem("att")->getValue() , "\n";
}
}

----------------When Run it gives me this. ---------------------

RequestID => XML::DOM::Attr=ARRAY(0x84d5908)
LetterHasSignatory => XML::DOM::Attr=ARRAY(0x84d699c)
LetterHasParameters => XML::DOM::Attr=ARRAY(0x84d6c3c)
ActionCode => XML::DOM::Attr=ARRAY(0x84d5740)

------------------------------------------------------------------

So as you can see it prints the $key valus out correctly, but the $value
seems to be an array.
How would I go about printing that out?

Thank you!
 
B

Ben Morrow

Quoth "-Brad- said:
Hi all, Im using the XML::DOM module to process an xml document but having a
few problems.
Im trying to loop though all the node attributes and retreive their values.
But having a few promlems.

The Perl code I have so far is
----------------When Run it gives me this. ---------------------

RequestID => XML::DOM::Attr=ARRAY(0x84d5908)
LetterHasSignatory => XML::DOM::Attr=ARRAY(0x84d699c)
LetterHasParameters => XML::DOM::Attr=ARRAY(0x84d6c3c)
ActionCode => XML::DOM::Attr=ARRAY(0x84d5740)

------------------------------------------------------------------

So as you can see it prints the $key valus out correctly, but the $value
seems to be an array.
How would I go about printing that out?

perldoc Data::Dumper
perldoc Data::Dump (get it from CPAN: I much prefer it to Dumper).

Ben
 
B

-Brad-

Hi Ben thanks for your reply, I've used Dumer to have a look at the array
and its quite confusing. I can attach a sample if you wish.
But all I would like to retreive is the value, so the end result is.

RequestID => 11112
LetterHasSignitory => True
etc ....

Thank you!


Quoth "-Brad- said:
Hi all, Im using the XML::DOM module to process an xml document but having a
few problems.
Im trying to loop though all the node attributes and retreive their values.
But having a few promlems.

The Perl code I have so far is
----------------When Run it gives me this. ---------------------

RequestID => XML::DOM::Attr=ARRAY(0x84d5908)
LetterHasSignatory => XML::DOM::Attr=ARRAY(0x84d699c)
LetterHasParameters => XML::DOM::Attr=ARRAY(0x84d6c3c)
ActionCode => XML::DOM::Attr=ARRAY(0x84d5740)

------------------------------------------------------------------

So as you can see it prints the $key valus out correctly, but the $value
seems to be an array.
How would I go about printing that out?

perldoc Data::Dumper
perldoc Data::Dump (get it from CPAN: I much prefer it to Dumper).

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by
an
increasing number of user complaints ... As of June,... the Arpanet
contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
(e-mail address removed)
 
B

Ben Morrow

[please learn to quote properly]

Quoth "-Brad- said:
Hi Ben thanks for your reply, I've used Dumer to have a look at the array
and its quite confusing. I can attach a sample if you wish.
But all I would like to retreive is the value, so the end result is.

RequestID => 11112
LetterHasSignitory => True
etc ....

Hmmm... I have misunderstood the problem :).
Try reading perldoc XML::DOM::Attr.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,268
Messages
2,571,095
Members
48,773
Latest member
Kaybee

Latest Threads

Top