PHP: Need help with simple XML.

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-04-15T14:39:36Z Indexed on 2010/04/15 14:43 UTC
Read the original article Hit count: 125

Filed under:
|

I am beginner in PHP. I am trying to parse this xml file.

<relationship>
 <target>
  <following type="boolean">true</following>
  <followed_by type="boolean">true</followed_by>
  <screen_name>xxxx</screen_name>
  <id type="integer">xxxx</id>
 </target>
</relationship>

I need to get the value of the field 'following type="boolean" ' and here's my code -

$xml = simplexml_load_string($response);

foreach($xml->children() as $child)
{
      if ($child->getName() == 'target')
      {
       foreach($child->children() as $child_1)
       if ( $child_1->getName() == 'following')
       {
        $is_my_friend = (bool)$child_1;
        break;
       }
       break;
      }
}

but I am not getting the correct output. I think the ' type="boolean" ' part of the field is creating problems. I know this might be a very trivial problem. Kindly bear with my ignorance. Please help.

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml