gpt4 book ai didi

xml-parsing - VBA 强制 SAX 编码 UTF-8 并缩进

转载 作者:行者123 更新时间:2023-12-04 11:46:58 30 4
gpt4 key购买 nike

我正在编写 VBA 来导出 xml。
我使用 SAXXMLReader 因为我需要非常缩进的输出。

这就是我希望声明的样子:

<?xml version="1.0" encoding="UTF-8"?>

结果是这样的:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>

为什么 SAX 忽略我的编码选择以及如何强制它使用 8.
Sub XML_Format_Indent_Save(xmlDoc1 As MSXML2.DOMDocument60, strOutputFile As String)
Dim xmlWriter As MSXML2.MXXMLWriter60
Dim strWhole As String

Set xmlWriter = CreateObject("MSXML2.MXXMLWriter")
xmlWriter.omitXMLDeclaration = False
xmlWriter.Indent = True
xmlWriter.Encoding = "utf-8"
With CreateObject("MSXML2.SAXXMLReader")
Set .contentHandler = xmlWriter
.putProperty "http://xml.org/sax/properties/lexical-handler", xmlWriter
.Parse xmlDoc1
End With
strWhole = xmlWriter.output
ExportStringToTextFile strOutputFile, strWhole
End Sub

最佳答案

从我在另一篇文章中读到的,您需要设置 .byteOrderMarktruefalse , 否则 .encoding被忽略。

关于xml-parsing - VBA 强制 SAX 编码 UTF-8 并缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37670040/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com