Page 1 of 1

XML php parser

Posted: Wed Jul 22, 2009 10:00 am
by rflopes
Hi.

i'm trying to take some information from xml data created with mxgraph.
example of the xml.

Code: Select all

<mxGraphModel>
<root>
<mxCell id="5"/>
    <mxCell id="1" parent="0"/>
    <mxCell id="2" value="login" parent="1" vertex="1">
      <mxGeometry x="90" y="100" width="80" height="30" as="geometry"/>
    </mxCell>
</root>
</mxGraphModel>
example of the php file

Code: Select all

for ($i=0;$i<3;$i++){
      foreach($xml->mxCell[$i]->attributes() as $a => $b)
      {
         echo $a."=",$b."               ";
      }
      echo "<br>";
     }
If i have de xml file in that format it gives me an error

Code: Select all

Fatal error: Call to a member function attributes() on a non-object in C:\AppServ\www\xml.php on line 6
But if i put the xml file without the <mxGraphModel> and </mxGraphModel> i can see the mxCell parameters.

Code: Select all

id=5
id=1 parent=0
id=2 value=login parent=1 vertex=1
What could be the error?

thanks,
Ricardo Lopes