This module allows you to indent XML before saving it to a file without using VB string functions. It does the work with an extremely small amount of code and does it properly using an XSL transformation instead of a recursive function.
This module is the result of this thread. I want to extend a huge "thank you" to MartinLiss for reasearching XSL transformations and solving this issue.
It will transform your XML from this:
to this:Code:<Values><FirstName>Rod</FirstName><LastName>Stephenshgsgfs</LastName><Street>1234 Programmer Place</Street><City>Bugsville</City><State>CO</State><Zip>80276</Zip></Values>
Code:<Values> <FirstName>Rod</FirstName> <LastName>Stephenshgsgfs</LastName> <Street>1234 Programmer Place</Street> <City>Bugsville</City> <State>CO</State> <Zip>80276</Zip> </Values>
Attached is the module and a small sample project.
To use it in any project all you have to do is add a reference to any version of MSXML.dll to your poject then call IndentXML() and pass a DOMDocument (or DOMDocument26, DOMDocument30 or DOMDocument40) object to the sub. After that the .xml property of that DOMDocument will be tabbed properly.
UPDATES:
11/16/2005 - Added 2 optional arguments to the IndentXML subroutine:
1) bUnindent - Boolean value telling wether or to unindent the XMLDOM object passed into oXMLDoc.
2) bLeaveHeader - Removes a problems from the last version where a tag was automatically added to the top of the document. If you want this tag back, set this parameter to true.




Reply With Quote