Getting Data from inside a node in XMl with PHP

前端 未结 2 1774
忘了有多久
忘了有多久 2021-01-16 10:44

So im not sure what or how to really describe what i need but hopefully someone will understand.

single element of the total xml file looks like this:

for         


        
相关标签:
2条回答
  • 2021-01-16 10:58

    try this

    $xml = simplexml_load_file("books.xml") 
       or die("Error: Cannot create object");
    
      foreach($xml->children() as $books){
    foreach($books->children() as $book => $data){
      echo $data->id;
      echo $data->title;
      echo $data->author;
      echo "<br />";
    }
    

    }

    0 讨论(0)
  • 2021-01-16 11:11

    Assuming your Event nodes have one parent (ie <Events><Event>...</Event><Event>...</Event></Events>):

    $xml = simplexml_load_file($file_xml);
    
    foreach($xml->Event as $event) {
        $idAttr = 'ID';
    
        $event_id = (string) $event->attributes()->$idAttr;
        $venue_id = (string) $event->Venue->attributes()->$idAttr;
    
        $venue_img_2 = (string) $event->Venue->Image->Url;
    }
    
    0 讨论(0)
提交回复
热议问题