Sunday, March 14, 2010

Read xml with php

An example to parse xml with php.

We have the following xml:


< catalogues >
< services >
< service code="RCA01" name="Consultatie initiala" servicetype="RECI" tariff="14.42" validfrom="2005-01-01">
< service code="RCA02" name="Consultatie de control" servicetype="RECC" tariff="9.56" validfrom="2005-01-01">
< / services>
< / catalogues>





$document = new DOMDocument();
$document->load( 'Nomenclators.xml' );

$sites = $document->getElementsByTagName( "Service" );
echo "Begin load";
foreach( $sites as $site )
{
$code = $site->getAttribute("code");
$name = $site->getAttribute("name");
$tariff = $site->getAttribute("tariff");
$serviceType = $site->getAttribute("serviceType");
$validFrom = $site->getAttribute("validFrom");
$validTo = $site->getAttribute("validTo");
}
echo "End load";

No comments:

Post a Comment