php生成xml文件

 时间:2026-02-14 12:36:38

1、$doc=new DOMDocument("1.0","utf8");$doc->formatOutput=true;

$doc->save("aaa.xml");//保存文件

输入本地网址显示空白页面,但是本地文件夹中生成xml文件

php生成xml文件

2、//这里注意了 生成元素只能在标签里面//使用createelement来创建一个标签$root=$doc->createElement("root");////将root标签添加xml$doc->appendchild($root);

php生成xml文件

php生成xml文件

3、//在root创建version标签$version=$doc->createElement("version");$versionTextNode=$doc->createTextNode("1.0");$version->appendchild($versionTextNode);当<root>标签中有值时就可以显示完整的<root>标签了

php生成xml文件

4、$info=$doc->createElement("Info");$infoTextNode=$doc->createTextNode("xml");$info->appendchild($infoTextNode);$root->appendchild($info);//创建<info>标签

php生成xml文件

php生成xml文件

5、//xml标签都是嵌套方式生成的

//比如生成<user>标签

$user=$doc->createElement("user");

$root->appendchild($user);

php生成xml文件

6、如在<user>标签里生成其他标签就要

$user=$doc->createElement("user");$name=$doc->createElement("name");$nameTextNode=$doc->createTextNode("于振海");$name->appendchild($nameTextNode);$user->appendchild($name);$root->appendchild($user);

php生成xml文件

7、$url=$doc->createElement("url");$urlTextNode=$doc->createTextNode("http://www.yuzh.com");$url->appendchild($urlTextNode);$user->appendchild($url);$author=$doc->createElement("author");$authorTextNode=$doc->createTextNode("da海");$author->sex=$doc->createElement("sex");$authorTextNode->sexTextNode=$doc->createTextNode("男");$author->sex->appendchild($authorTextNode->sexTextNode);$author->appendchild($authorTextNode);$user->appendchild($author);

php生成xml文件

  • Discuz!x3新功能:怎么取消必填注册邮箱
  • 织梦CMS实现自动更新主页功能的方法
  • linux如何设置nginx开机启动
  • php如何读取指定文件的内容
  • 易语言取文件尺寸
  • 热门搜索
    手抄报的图案 手抄报我的中国梦 庆十一手抄报 与诗同行手抄报 清明节手抄报设计图 做文明人手抄报 法制进校园手抄报 为国家富强而奋斗的杰出人物手抄报 做美德少年手抄报 最漂亮普通话手抄报