Page 1 of 1

xml parser

Posted: Fri Mar 09, 2012 4:56 pm
by srdva59
hi,
i have this xml

<m time="2012-03-09T11:14:20+00:00" timestamp="1331291660">
<ma id="1219457" xsid="0">
<time>2012-03-09T19:30:00+00:00</time>
<gru id="8388">Nacional</gru>
<ht id="2325">Teste</ht>
<at id="8919">Teste2</at>
<results />
<mar did="6" name="Under">
<ofr id="95690814" n="2" ot="0" last_updated="2012-03-09T11:13:35+00:00" flags="1" bmoid="1000095485">
<ors i="0" time="2012-03-08T18:59:22+00:00" starting_time="2012-03-09T19:30:00+00:00">
<a1>4</a1>
<a2>3.5</a2>
<a3>4</a3>
<a4>2</a4>
<a5>8</a5>
</ors>
</ofr>
</mar>
</ma>
</m>

and this code:

$DOMDocument = new DOMDocument( '1.0' , 'utf-8' );
$DOMDocument->preserveWhiteSpace = false;
$DOMDocument->loadXML( $xml );
foreach ( $DOMDocument->getElementsByTagName( '*' ) as $Nodes ) {
foreach ( $Nodes->getElementsByTagName( '*' ) as $Node ) {
$Data[ $Node->parentNode->nodeName ][ $Node->nodeName ] = $Node->nodeValue;

}

with this code i can load the value of the a1 and a2 etc but i need load the name of the mar ( Under ) and the did.

how can i do this?
thanks
:)

Re: xml parser

Posted: Fri Mar 09, 2012 6:19 pm
by Celauran

Code: Select all

$xml = new SimpleXMLElement(file_get_contents('foo.xml'));
echo $xml->ma->mar['name'];