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
https://forums.phpfreaks.com/topic/112315-xml-dom-parsing/
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
https://forums.phpfreaks.com/topic/112315-xml-dom-parsing/#findComment-576639
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.