Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么MSXML中的createProcessingInstruction会生成不完整的输出?_Xml_Vba_Ms Access_Msxml - Fatal编程技术网

为什么MSXML中的createProcessingInstruction会生成不完整的输出?

为什么MSXML中的createProcessingInstruction会生成不完整的输出?,xml,vba,ms-access,msxml,Xml,Vba,Ms Access,Msxml,以下VBA代码生成作为输出 Dim XML As New DomDocument Dim pi As IXMLDOMProcessingInstruction '.... some code that sets the root element of the document Set pi = XML.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'") XML.insertBefore p

以下VBA代码生成
作为输出

Dim XML As New DomDocument 
Dim pi As IXMLDOMProcessingInstruction

'.... some code that sets the root element of the document

Set pi = XML.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'")
        XML.insertBefore pi, XML.documentElement

为什么不使用
encoding=“UTF-8”

UTF-8是默认编码。您指定的内容是冗余的,因此序列化程序可能会忽略它。但是,
version
字段不是可选字段。如果文件有XML声明,则.

不是处理指令。该构造称为,并遵循与实际处理指令不同的规则。创建名为“xml”的PI格式不正确;以“xml”开头的名称是


要更改序言的格式,您需要设置“version”、“encoding”或简单地设置“ommitXMLDeclaration”以将其完全删除,因为1.0和UTF-8是默认值。

version也是默认值。还是在输出中。嗯,谢谢你接受我的答案,但我倾向于认为Bobince的更好。显然,尽管看起来就像一条处理指令,+1验证了带有SAX内容处理程序的XMLWriter生成了OP期望的输出<代码>