# Format multi-lined indented XML

**URL:** <https://forum.kirupa.com/t/format-multi-lined-indented-xml/273271>\
**Category:** flash\
**Created:** [October 13, 2008, 8:46pm UTC](https://forum.kirupa.com/t/format-multi-lined-indented-xml/273271 "2008-10-13T20:46:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalamus](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thalamus](https://forum.kirupa.com/u/thalamus)\
**Post date:** [October 13, 2008, 8:46pm UTC](https://forum.kirupa.com/t/format-multi-lined-indented-xml/273271/1 "2008-10-13T20:46:22Z")

</div>

Hello:

I’m working with Senocular’s code for formatting XML from the tutorial. I am developing a RIA that loads and writes to XML, and want to keep the XML file readable for my edification (not one ridiculously-long line.)

[http://www.kirupa.com/web/xml/XMLmanageData7.htm](http://www.kirupa.com/web/xml/XMLmanageData7.htm)

Trying to get this to work first with some simple in-line XML:  
var x1:XML = new XML("\<item\>\<a id=‘1’ /\>\<a id=‘2’ /\>\<a id=‘3’ /\>\</item\>");

// formats XML into a multi-lined, indented format  
// a good toString replacement for XML with ignoreWhite = true  
XMLNode.prototype.format = function(indent) {  
if (indent == undefined) {  
indent = “”;  
}  
var str = “”;  
var currNode = this.firstChild;  
do {  
if (currNode.hasChildNodes()) {  
str += indent + currNode.cloneNode(0).toString().slice(0, -2) + "\>  
";  
str += currNode.format(indent + " ");  
str += indent + “\</” + currNode.nodeName + "\>  
";  
} else {  
str += indent + currNode.toString() + "  
";  
}  
} while (currNode = currNode.nextSibling);  
return str;  
};

Need to know the appropriate syntax to CALL this function so I can trace the output to see if it’s worked. Thanks.
