A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Need help XML tree i flash

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    3
    When I retreive data from a file (demo.xml) flash interprets "\n" and TABs as a childnode.
    That makes it hard for me to handle the date.
    Is this a known problem?
    Is ther a solution?
    Or is it a "I-am-to-stupit"-problem, than please clue me?!

    XML as a CGI-output is no problem, but I like to avoid writing all my xml-files in a single-Line...

  2. #2
    Senior Member SJT's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    2,563
    this is a problem with Flash reading whitespace as nodes, you need to parse the white space out.
    moock has written this function to do it for you:

    Code:
    function cutWhitespace (xmlObjectToParse) {
    	for (var i = 0; i < xmlObjectToParse.childNodes.length; i++) {
    		if (xmlObjectToParse.childNodes[i].nodeType == 3) {
    			var j = 0;
    			var empty = true;
    			for (j=0; j<xmlObjectToParse.childNodes[i].nodeValue.length; j++) {
    				if (xmlObjectToParse.childNodes[i].nodeValue.charCodeAt(j)>32) {
    					empty = false;
    				}
    				break;
    			}
    		}
    		if (empty) {
    			xmlObjectToParse.childNodes[i].removeNode();
    		}
    		for (var k = 0; k &lt; xmlObjectToParse.childNodes.length; k++) {
    			var cutSubNodes = xmlObjectToParse.childNodes[k];
    			cutWhitespace(cutSubNodes);
    		}
    	}
    }

  3. #3
    Junior Member
    Join Date
    Jun 2001
    Posts
    2

    Lightbulb Not broken - this is the way XML works

    [QUOTE]Originally posted by schwani
    [B]When I retreive data from a file (demo.xml) flash interprets "\n" and TABs as a childnode.
    That makes it hard for me to handle the date.
    Is this a known problem?

    The XML DOM is defined so that whitespace _is_ important. That means it gets its own node, and all of the problems that you have mentioned. You can parse it out, or there is a property that allows you to tell certain versions of the player to ignore whitespace.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center