Home > php教程 > php手册 > php生成XML文档源代码

php生成XML文档源代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:38:54
Original
942 people have browsed it

生成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>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template