提问人:VolleyballAddictSandiego 提问时间:6/7/2016 更新时间:1/21/2021 访问量:1351
VBA 强制 SAX 对 UTF-8 进行编码并缩进
VBA force SAX to encode UTF-8 and indent
问:
我正在编写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
答:
0赞
Vince42
3/18/2017
#1
根据我在另一篇文章中读到的内容,您需要设置为 或 ,否则将被忽略。.byteOrderMark
true
false
.encoding
评论