Using XML class's static properties
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> public var usersXML:XML=<users> <user id="1">A</user> <user id="2">B</user> </users>; public function togglePretty():void{ XML.prettyPrinting = !XML.prettyPrinting; myTextArea.text = usersXML.toString(); } </mx:Script> <mx:TextArea id="myTextArea" width="200" height="100" /> <mx:Button label="Toggle Pretty Printing" click="togglePretty()" /> </mx:Application>