2010-07-26 88 views
1

我有严重的问题,访问特定的XML文件的节点:SimpleXML的问题访问XML节点

http://write.fm/cqsmrf5

与print_r的我得到以下结果:

SimpleXMLElement Object 
(
    [RecordSet] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [dataSource] => testdatabase 
        [totalRecordCount] => 3573 
       ) 

      [Record] => Array 
       (
        [0] => SimpleXMLElement Object 
         (
          [@attributes] => Array 
           (
            [counter] => 1 
           ) 

          [Fields] => SimpleXMLElement Object 
           (
            [Field] => Array 
             (
              [0] => Barcelona 
              [1] => 1 
             ) 

           ) 

         ) 

        [1] => SimpleXMLElement Object 
         (
          [@attributes] => Array 
           (
            [counter] => 2 
           ) 

          [Fields] => SimpleXMLElement Object 
           (
            [Field] => Array 
             (
              [0] => Cádiz 
              [1] => 2 
             ) 

           ) 

         ) 

       ) 

     ) 

我想通过访问命令 print $xml->recordset->record[0]->fields->field[0]; 但我只收到错误:

Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/test.php on line 18 

任何人都可以帮助我。 在此先感谢。

回答

2

XML is case-sensitive。尝试

$xml->RecordSet->Record[0]->Fields->Field[0]; // Barcelona 
+1

谢谢, 我很新的东西。对不起,我的小问题:-) – 2010-07-26 12:31:11