ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved