dongshi3605 2011-05-10 09:02
浏览 22
已采纳

在php中创建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>

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

  • 写回答

10条回答 默认 最新

  • douan3414 2011-05-10 09:16
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

悬赏问题

  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题