I had this exact problem just last week. I couldn't figure out a solution, so I simply removed all carriage returns and tabs from the raw XML data. Here's the function that I wrote to clean things up. Simply add on onData event handler to your XML loading and then call this function with the raw XML data string.

I didn't try the condenseWhite option that Duncan suggests, but if that works, I'll kick myself. Either way, this solution works well for me.

function cleanXML(xmlString):String{
        var cleanString:String = xmlString;
        
        // remove any processing instructions in the XML data
        while (cleanString.indexOf("<?") != -1){
                var startIndex = cleanString.indexOf("<?");
                var endIndex = cleanString.indexOf("?>") + 2;
                var dirtyString:String = cleanString.slice(startIndex, 
endIndex);
                cleanString = cleanString.split(dirtyString).join("");
        }
        
        // remove any extranieous \t\n\r characters in the XML data
        cleanString = cleanString.split("\r").join("");
        cleanString = cleanString.split("\n").join("");
        cleanString = cleanString.split("\t").join("");
        
        return cleanString;
}

Note that I'm also removing all processing instructions from the XML as well because Flash can't handle them (my clients are using Altova StyleVision to edit the content and that puts an extra processing instruction block at the top of the XML file).


Hope that helps,
Josh

On Jan 24, 2006, at 3:34 PM, david kraftsow wrote:

Hi.

Whats the easiest way to strip out that annoying whitespace from your xml nodes? I have a lovely human-readable xml file with tons of carriage returns and tabs. When I load it into a flash XML object the leaf/ content nodes all have tabs and carriage returns in them. Setting the ignoreWhite property does nothing. [?] Example:

<root_1 attr_1="blahblah">
   <node_1>
           <![CDATA[
                   Leaf content 1 blah blah blah.
            ]]>
   </node_1>
</root_1>

When I parse out that leaf content I get a string like "\n \n Leaf content...." Very annoying. I don't have to write a traversal method to strip it all out do I? Surely there is a better way!
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to