Lijoyx Posted June 28, 2008 Share Posted June 28, 2008 hai friends, i am trying to parse an xml file using dom the thing is i am not used to it. now u have to help me. given below is the xml file. <?xml version="1.0"> <Catalog> <Category> <Name>Business to Business</Name> <Site> <Id>Creed</Id> <PopularityRank>4366</PopularityRank> <Description>A simple desc</Description> <HasRecurringProducts>true</HasRecurringProducts> <Commission>75</Commission> </Site> <Site> <Id>Creed</Id> <PopularityRank>4366</PopularityRank> <Description>A simple desc</Description> <HasRecurringProducts>true</HasRecurringProducts> <Commission>75</Commission> </Site> </Category> </Catalog> now i want to print all the ids and commisions. Can anyone help me. Quote Link to comment Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 <?php $xmlstr = <<<_XML <?xml version="1.0"?> <Catalog> <Category> <Name>Business to Business</Name> <Site> <Id>Creed</Id> <PopularityRank>4366</PopularityRank> <Description>A simple desc</Description> <HasRecurringProducts>true</HasRecurringProducts> <Commission>75</Commission> </Site> <Site> <Id>Creed 2</Id> <PopularityRank>5000</PopularityRank> <Description>Another simple desc</Description> <HasRecurringProducts>false</HasRecurringProducts> <Commission>7400</Commission> </Site> </Category> </Catalog> _XML; $xml = simplexml_load_string( $xmlstr ); $sites = $xml->xpath("/Catalog/Category/Site"); foreach ( $sites as $site ) { echo "<p>{$site->Id} = {$site->Commission}</p>"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.