ホームページ  >  記事  >  バックエンド開発  >  PHP による XML ドキュメントのソース コードの生成_PHP チュートリアル

PHP による XML ドキュメントのソース コードの生成_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:40:24863ブラウズ

XML ソースコードを生成:

<span style="color: rgb(0, 0, 0);"> $dom <span style="color: rgb(0, 0, 204);">=</span> 新しい 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> もし<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><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> 戻る <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>ファイル名<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> もし<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>ファイル名<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> 戻る <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);">/ルートノードを参照します </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);">値</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.comtru​​ehttp://www.bkjia.com/PHPjc/486219.html技術記事 XML ソース コードを生成します: $dom = new DOMDocument () ; if ( ! $dom ) { printf ( "XML の構築に失敗しました!" ) } if ( FALSE == ( $dom -load ( $ filename ) ) ) { add_root (...
)
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。