Parse XML with Namespace using SimpleXML

前端 未结 6 968
独厮守ぢ
独厮守ぢ 2020-11-21 23:45

I have this as xml:


    
        &         


        
6条回答
  •  爱一瞬间的悲伤
    2020-11-22 00:38

    Having worked a lot with simplexml, this is how I do it.

    The magic trick if you already have an element and just want to get it's different namespaced children, say for a structure like this:

    
    My test entry
    
    A type
    
    

    Is to send TRUE as the second parameter to the children function:

      $title = (string) $entry->title;
      $gd = $entry->children('gd', TRUE);
      $attrs = $gd->when->attributes();
      $startTime = (string) $attrs->startTime;
      $gc = $entry->children('gc', TRUE);
      $notes = (string) $gc->notes();
    

提交回复
热议问题