Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick and easy way to Indent your DOM generated XML

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
I'll try to make this short, sweet, and to the point...

When you use Microsoft's Dom Object to create or modify XML on the fly, you tend to get an out put of 1 single continuous line of tags...

Instead of the nice and neat indented XML that is easier to read...

Here is a method (written with VB) to Indent your generated XML for you...

Code:
Function Indent(dom As DOMDocument) As DOMDocument
  Set Indent = IIf(dom.loadXML(Replace(dom.xml, "><", ">" & vbCrLf & "<")), dom, Nothing)
End Function

I came up with the idea after reading this article:

Though it is a vb function, it should be easily translated to any other language with a Replace function, and access to the MSXML dom objects...

Hope This Helps ;-)
-Josh


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top