我正在编写 VBA 来导出 xml。我使用 SAXXMLReader 因为我需要非常缩进的输出。
这就是我希望声明的样子:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
结果如下:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
Run Code Online (Sandbox Code Playgroud)
为什么 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1040 次 |
| 最近记录: |