xml::dom parsing complex xml problem
by Chris Oldfield other posts by this author
Jan 26 2005 12:09PM messages near this date
view in the new Beta List Site
RE: XML::dom parsing complex xml problem
|
Re: xml::dom parsing complex xml problem
& XSLT I'm trying to parse a complex xml message, using XML::DOM for the first
time, part of which has a format of
<Instructions>
<Agent>
<Contacts>
<Contact>
<TelephoneNumbers>
<TelephoneNumber Type="Mobile"> 777777</TelephoneNumber>
<TelephoneNumber Type="Home"> 88888</TelephoneNumber>
<TelephoneNumber Type="Work"> 99999</TelephoneNumber>
</TelephoneNumbers>
</Contact>
</Contacts>
<Address/>
<TelephoneNumbers>
<TelephoneNumber> 1111111</TelephoneNumber>
</TelephoneNumbers>
</Agent>
</Instruction>
</Instructions>
I can access the telephone numbers within Contact
foreach my $Instruction($doc-> getElementsByTagName('Instruction')){
foreach my $Agent($Instruction-> getElementsByTagName('Agent')){
foreach my $Contact($Agent-> getElementsByTagName('Contact')){
foreach my
$TelephoneNumber($Contact-> getElementsByTagName('TelephoneNumber')){
print "\t\t\t\t",
$TelephoneNumber-> getAttribute('Type'),": ",
$TelephoneNumber-> getFirstChild->getNodeValue(), "\n";
}
}
}
foreach my
$TelephoneNumber($Agent-> getElementsByTagName('TelephoneNumber')){
print "\t\tTelephone Number:
",$TelephoneNumber-> getFirstChild->getNodeValue(), "\n";
}
}
The last loop returns not only the the telephone number relating to the
agent but also those relating to contact. I under stand why it's doing this.
How do I qualify the call to just return the telephone node(s) directly
relating to <Agent> ignoring those within <Contact>?
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Chris Oldfield
Grant McLean
Chris Oldfield
Grant McLean
|