Results 1 to 10 of 10

Thread: Indent XML (without recursion)

Threaded View

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Indent XML (without recursion)

    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:
    Code:
    <Values><FirstName>Rod</FirstName><LastName>Stephenshgsgfs</LastName><Street>1234 Programmer Place</Street><City>Bugsville</City><State>CO</State><Zip>80276</Zip></Values>
    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>

    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.
    Attached Files Attached Files
    Last edited by eyeRmonkey; Nov 16th, 2005 at 07:17 PM.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width