use MXXMLWriter and SAXXMLReader to make a well formated xml file (indent)

    Dim xmlDoc As New DOMDocument30
    'Create the SAX reader.
    Dim rdr As New SAXXMLReader30
    'Create the XML writer.
    Dim wrt As New MXXMLWriter30

    'Load the DOM document.
    xmlDoc.async = False
    xmlDoc.Load  App.Path & "\books.xml"

    'Set properties on the XML writer.
    wrt.byteOrderMark = True
    wrt.omitXMLDeclaration = True
    wrt.indent = True

    'Set the XML writer to the SAX content handler.
    Set rdr.contentHandler = wrt
    Set rdr.dtdHandler = wrt
    Set rdr.errorHandler = wrt
    rdr.putProperty "http://xml.org/sax/properties/lexical-handler", wrt
    rdr.putProperty "http://xml.org/sax/properties/declaration-handler", wrt

    'Parse the DOMDocument object.
    rdr.parse xmlDoc

    'Show the results in the text box.
    debug.print wrt.output
This entry was posted in Code Snippets. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s