Generate XML with namespace URI in PHP

后端 未结 2 907
长情又很酷
长情又很酷 2021-01-15 13:30

Ho to make this \"simple\" xml with php using DOM? Full code will be welcomed.



        
2条回答
  •  春和景丽
    2021-01-15 13:41

    Here is the code:

    createElement('rss');
    $dom->appendChild($rss);
    
    $version = $dom->createAttribute('version');
    $rss->appendChild($version);
    
    $value = $dom->createTextNode('2.0');
    $version->appendChild($value);
    
    $xmlns_wp = $dom->createAttribute('xmlns:wp');
    $rss->appendChild($xmlns_wp);
    
    $value = $dom->createTextNode('http://url.com');
    $xmlns_wp->appendChild($value);
    
    $xmlns_dc = $dom->createAttribute('xmlns:dc');
    $rss->appendChild($xmlns_dc);
    
    $value = $dom->createTextNode('http://url2.com');
    $xmlns_dc->appendChild($value);
    
    $channel = $dom->createElement('channel');
    $rss->appendChild($channel);
    
    $items = $dom->createElement('items');
    $channel->appendChild($items);
    
    $sometags = $dom->createElement('sometags', '');
    $items->appendChild($sometags);
    
    $wp_status = $dom->createElement('wp:status', '');
    $items->appendChild($wp_status);
    
    echo $dom->saveXML();
    ?>
    

    It outputs:

    
    
      
        
          
          
        
      
    
    

    Fore more help: http://us2.php.net/manual/en/book.dom.php

提交回复
热议问题