php生成XML文档源代码_PHP教程

WBOY
Freigeben: 2016-07-13 17:40:24
Original
873 Leute haben es durchsucht

生成XML源代码:

<span style="color: rgb(0, 0, 0);">    $dom <span style="color: rgb(0, 0, 204);">=</span> new DOMDocument<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>     if<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span><span style="color: rgb(0, 0, 204);">$</span>dom<span style="color: rgb(0, 0, 204);">)</span><br>     <span style="color: rgb(0, 0, 204);">{</span><br>         printf<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 255);">"构造XML失败! "</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>         return <span style="color: rgb(0, 0, 204);">-</span>3999<span style="color: rgb(0, 0, 204);">;</span><br>     <span style="color: rgb(0, 0, 204);">}</span><br> <br>     if<span style="color: rgb(0, 0, 204);">(</span>FALSE <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>load<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>filename<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><br>     <span style="color: rgb(0, 0, 204);">{</span><br>         add_root<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>         if<span style="color: rgb(0, 0, 204);">(</span>FALSE <span style="color: rgb(0, 0, 204);">=</span><span style="color: rgb(0, 0, 204);">=</span> <span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>load<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>filename<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">)</span><br>         <span style="color: rgb(0, 0, 204);">{</span><br>             return <span style="color: rgb(0, 0, 204);">-</span>3999<span style="color: rgb(0, 0, 204);">;</span><br>         <span style="color: rgb(0, 0, 204);">}</span><br>     <span style="color: rgb(0, 0, 204);">}</span><br> <br>     <span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">/引用root根节点</span><br>     $f_node <span style="color: rgb(0, 0, 204);">=</span> $dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>getElementsByTagName<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>parent_node<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>item<span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span> <br>     if<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">!</span><span style="color: rgb(0, 0, 204);">$</span>f_node<span style="color: rgb(0, 0, 204);">)</span><br>     <span style="color: rgb(0, 0, 204);">{</span><br>         $root <span style="color: rgb(0, 0, 204);">=</span> $dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>getElementsByTagName<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(255, 0, 255);">root</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>item<span style="color: rgb(0, 0, 204);">(</span>0<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span> <br>         <span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">/创建父节点</span><br>         $f_node <span style="color: rgb(0, 0, 204);">=</span> $dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>createElement<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>parent_node<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>         $f_node <span style="color: rgb(0, 0, 204);">=</span> $root<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>appendChild<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>f_node<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>     <span style="color: rgb(0, 0, 204);">}</span>    <br>     <span style="color: rgb(0, 0, 204);">/</span><span style="color: rgb(0, 0, 204);">/创建节点</span><br>     $item_node <span style="color: rgb(0, 0, 204);">=</span> $dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>createElement<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>node<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>     $item_node <span style="color: rgb(0, 0, 204);">=</span> $f_node<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>appendChild<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>item_node<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>     $item_value <span style="color: rgb(0, 0, 204);">=</span> $dom<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>createTextNode<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span><span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br>     $item_node<span style="color: rgb(0, 0, 204);">-</span><span style="color: rgb(0, 0, 204);">></span>appendChild<span style="color: rgb(0, 0, 204);">(</span><span style="color: rgb(0, 0, 204);">$</span>item_value<span style="color: rgb(0, 0, 204);">)</span><span style="color: rgb(0, 0, 204);">;</span><br> </span>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486219.htmlTechArticle生成XML源代码: $dom = new DOMDocument ( ) ; if ( ! $ dom ) { printf ( "构造XML失败!" ) ; return - 3999 ; } if ( FALSE = = ( $ dom - load ( $ filename ) ) ) { add_root (...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!