Jump to content

xml dom parsing


Lijoyx

Recommended Posts

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.

Link to comment
Share on other sites

<?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>";

        }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.