Grabbed this off actionscript.org.... thought I'd share it with the group. 
http://www.actionscript.org/actionscripts_library/XML_Object/more3.shtml

Had to tweak it a lil to get it to work but i think it was worth it.

Credit goes to Ken Goulding | website http://www.eyeriss.com
for the original code.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml " preloader=""
    initialize="this_init()" >
    <mx:TextArea id="outputTextArea" text="{output}" height="150" width="150" />
    <mx:Script>
    <![CDATA[
        public function this_init() {
            var x:XML = new XML("<root><test1>asdf</test1><test1><test2><test3></test3></test2></test1></root>");
            trace("x = " + toXMLString(x));
        }
        private var output;
        private function toXMLString(xmlObj, spacer){
            spacer = (spacer == undefined) ? "\t" : spacer;
            var xml_str = xmlObj.toString();
            var open, closed, tabs, node_str, eol, ts, last_closed;
            output = ""; eol=""; tabs = 0;
            open = xml_str.indexOf("<", 0);
            var tab_next = false;
                var i = 0;
                while (open != undefined and open != -1) {
                    if (open != -1) {
                        closed = xml_str.indexOf(">", open+1);
                        node_str = xml_str.substring(open, closed+1);
                        if (tab_next) {
                            tabs++;
                            tab_next = false;
                        }
                        if (node_str.indexOf("/") == 1) {
                            tabs--;
                        } else if (node_str.lastIndexOf("/") != node_str.length-2) {
                            tab_next = true;
                        }
                        ts = "";
                        for (var j = 0; j<tabs; j++) {
                            ts += spacer;
                        }
                        if (open == last_closed+1) {
                            eol = "\n"+ts;
                        } else if (open>0) {                       
                            eol = xml_str.substring(last_closed+1, open);
                        }
                        output += eol+node_str;
                    }
                    open = xml_str.indexOf("<", open+1);
                    last_closed = closed;
                }
            return output;
        }
    ]]>
    </mx:Script>
</mx:Application>



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to