Newbie learning simplexml_load_file

by hometutor 2 replies
This should help me get my start with this. I'm trying to parse an xml whose format is

Code:
//<Catalog>
//<Category>
//<Name>blah</Name>
//<Site>
//<Id>blah id</Id>
I copied a code and am trying to get just the id to give me a better understanding of the structure.

Code:
$html = "";
$url = "foo.xml";
$xml = simplexml_load_file($url);
for($i = 0; $i < 10; $i++){
	$id = $xml->Category->Name->Id[$i]->Id;

echo $id;

}
//echo $html;

echo $id.'<br>';
echo 'working';
I cannot get a value for id. Once I can understand that I believe I can get the other values I need.

Thank you for your help,

Rick
#programming #learning #newbie #simplexmlloadfile
Avatar of Unregistered
  • Profile picture of the author chickahoona
    Your "xml" is no xml...

    an xml looks like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <note>
        <id>512</id>
        <to>Tove</to>
       <from>Jani</from>
       <heading>Reminder</heading>
       <body>Don't forget me this weekend!</body>
    </note>
    {{ DiscussionBoard.errors[10153400].message }}
    • Profile picture of the author hometutor
      Originally Posted by chickahoona View Post

      Your "xml" is no xml...

      an xml looks like this:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <note>
          <id>512</id>
          <to>Tove</to>
         <from>Jani</from>
         <heading>Reminder</heading>
         <body>Don't forget me this weekend!</body>
      </note>
      I know thank you though. What I showed were the tags I need to drill down to get the ID hoping a knowledgeable person could help me with that.

      Rick
      {{ DiscussionBoard.errors[10154215].message }}
Avatar of Unregistered

Trending Topics