在php中创建xml时删除xml版本标记 [英] remove xml version tag when a xml is created in php

查看:90
本文介绍了在php中创建xml时删除xml版本标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此创建xml

I'm creating a xml using this

$customXML = new SimpleXMLElement('<abc></abc>');

在此上添加一些属性后,当我尝试打印它时 看起来像这样,

after adding some attributes onto this, when I try to print it it appears like this,

<?xml version="1.0"?>
<abc id="332"><params><param name="aa">33</param></params></abc>

有没有一种方法可以删除xml版本节点? 谢谢

Is there a way to remove the xml version node ? Thank you

推荐答案

理论上,您可以提供 LIBXML_NOXMLDECL选项用于保存文档时删除XML声明,但这仅在Libxml> = 2.6.21(和越野车).一种替代方法是使用

In theory you can provide the LIBXML_NOXMLDECL option to drop the XML declaration when saving a document, but this is only available in Libxml >= 2.6.21 (and buggy). An alternative would be to use

$customXML = new SimpleXMLElement('<abc></abc>');
$dom = dom_import_simplexml($customXML);
echo $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);

这篇关于在php中创建xml时删除xml版本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆