如何从输出中排除XML Prolog? [英] How do you exclude the XML prolog from output?

查看:62
本文介绍了如何从输出中排除XML Prolog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写 $ xml = new DOMDocument(); ,它会自动创建<?xml version = 1.0?> 。我不需要创建它。我怎么做?

I write $xml = new DOMDocument(); and it automatically creates <?xml version="1.0"?>. I need to NOT create it. How do i do that?

一种解决方案是搜索第一个>并在第一个<找到了。但是,我喜欢一种更好的方法。

One solution is to search the first ">" and strsub at the index at the first < found. But i like a nicer way to do this.

推荐答案

当您 saveXML ,将根元素作为 node 参数传递。仅根元素及其内容将被序列化,根之外的任何XML声明,doctype,注释或PI都将被序列化。

When you saveXML, pass in the root element as the node argument. Only the root element and its contents will be serialised, and not any XML declaration, doctype, comments or PIs outside the root.

$doc->saveXML($doc->documentElement);

或者,如果您需要其他内容,但又不需要多余的声明,则:

or, if you need the other stuff but just not the redundant declaration:

$result= '';
foreach($document->childNodes as $node)
    $result.= $document->saveXML($node)."\n";

这篇关于如何从输出中排除XML Prolog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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