SimpleXML and namespaces

后端 未结 3 1344
无人及你
无人及你 2020-12-07 03:02

I have following code.

 
  
   24
   6
           


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 03:47

    I would do it dynamically.

    $xml = @simplexml_load_string($path) // loads your valid xml data
    foreach($xml->channel->item as $entry) {
    
      $namespaces = $entry->getNameSpaces(true);
      foreach($namespaces as $ns=>$value)
      {
        $job = $entry->children($namespaces[$ns]);
        $author = (string)$job->creator;
    
        if ($author != "")
        {
          $someVariable = (string) $dc->creator;
        }
    }
    

提交回复
热议问题