代码之家  ›  专栏  ›  技术社区  ›  Norbert B. MJB

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

  •  5
  • Norbert B. MJB  · 技术社区  · 15 年前

    以下VBA代码生成 <?xml version="1.0"?> 作为输出。

    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" 漏掉了?

    2 回复  |  直到 15 年前
        1
  •  1
  •   Rob Kennedy    15 年前

    不管怎样,UTF-8是默认编码。您指定的是冗余的,所以序列化程序可能会忽略它。这个 version 不过,字段不是可选字段。如果文件有XML声明, the declaration must include the version field .

        2
  •  9
  •   bobince    15 年前

    <?XML?是 一种处理指令。&?XML?>构造称为 XML declaration 并对实际的处理指令遵循不同的规则。创建名为__xml_秷的PI格式不正确;以_xml_秷开头的名称为 reserved .

    要更改prolog的格式,需要 configure an XMLWriter ,设置__version_,__encoding__,或简单地__omitxmldeclaration__,将其全部删除,这是非常好的,因为1.0和utf-8是默认值。

    推荐文章