<!-- DOMDocument生成XML文件 -->
<?php
//声明一个DOMDocument对象
$_doc=new DOMDocument('1.0', 'utf-8');

//使用XML标准化输出
$_doc->formatOutput=true;

//使用createelement创建标签
$_root=$_doc->createElement('root');
$_version=$_doc->createElement('version');

//创建version标签字符串(值)
$_versionTextNode=$_doc->createTextNode('1.0');

//将该字符串插入version标签中
$_version->appendChild($_versionTextNode);

//将version标签插入root标签中
$_root->appendChild($_version);

//将root标签插入文件中
$_doc->appendChild($_root);

//生成XML文件
$_doc->save('test1.xml'); 
?> 


<!-- DOMDocument生成XML文件 -->
<?php
//声明一个DOMDocument对象
$_doc=new DOMDocument('1.0', 'utf-8');

//使用XML标准化输出
$_doc->formatOutput=true;

//使用createelement创建标签
$_root=$_doc->createElement('root');
$_version=$_doc->createElement('version');

//创建version标签字符串(值)
$_versionTextNode=$_doc->createTextNode('1.0');

//将该字符串插入version标签中
$_version->appendChild($_versionTextNode);

//将version标签插入root标签中
$_root->appendChild($_version);

//将root标签插入文件中
$_doc->appendChild($_root);

//生成XML文件
$_doc->save('test2.xml'); 
?>

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2022-02-11
  • 2021-06-16
  • 2021-07-11
  • 2022-02-13
  • 2021-07-24
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案