如何使用VB6和MSXML漂亮打印XML源?

前端之家收集整理的这篇文章主要介绍了如何使用VB6和MSXML漂亮打印XML源?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我几个月来一直在关注这个问题,我主要发现网站提出了同样的问题。

我发现的答案总是用于.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

猜你在找的VB相关文章