recherche
Maisonphp教程php手册php生成XML文档源代码

php生成XML文档源代码

Jun 13, 2016 am 10:38 AM
domdomdocumentnewphpprintfxml文档源代码生成

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

Déclaration
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Meilleurs paramètres graphiques
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Comment réparer l'audio si vous n'entendez personne
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Commandes de chat et comment les utiliser
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌

Outils chauds

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

SublimeText3 Linux nouvelle version

SublimeText3 Linux nouvelle version

Dernière version de SublimeText3 Linux

Télécharger la version Mac de l'éditeur Atom

Télécharger la version Mac de l'éditeur Atom

L'éditeur open source le plus populaire

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

VSCode Windows 64 bits Télécharger

VSCode Windows 64 bits Télécharger

Un éditeur IDE gratuit et puissant lancé par Microsoft