我几个月来一直在关注这个问题,我主要发现网站提出了同样的问题。
我发现的答案总是用于.NET或C或涉及XSLT。
经过几个月的研究,我已经提出了这一点。
Public Function PrettyPrintXML(XML As String) As String Dim Reader As New SAXXMLReader60 Dim Writer As New MXXMLWriter60 Writer.indent = True Writer.standalone = False Writer.omitXMLDeclaration = False Writer.encoding = "utf-8" Set Reader.contentHandler = Writer Set Reader.dtdHandler = Writer Set Reader.errorHandler = Writer Call Reader.putProperty("http://xml.org/sax/properties/declaration-handler",_ Writer) Call Reader.putProperty("http://xml.org/sax/properties/lexical-handler",_ Writer) Call Reader.parse(XML) PrettyPrintXML = Writer.output End Function
使用文档:
Public Function PrettyPrintDocument(Doc As DOMDocument60) As String PrettyPrintDocument = PrettyPrintXML(Doc.XML) End Function