XML php parser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rflopes
Forum Newbie
Posts: 1
Joined: Wed Jul 22, 2009 9:53 am

XML php parser

Post 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
Post Reply