A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: XML Editors and ignoreWhite

  1. #1
    Member
    Join Date
    Feb 2001
    Posts
    56
    Hey everyone-
    I'm having an issue with the internal parser within Flash.
    I went to the macromedia site and was looking at their "ignoreWhite" attribute for XML nodes. I can't seem to get it to work.
    It really has to due with XML editors - some decide that they know what's best and "reformat" all of the XML data with white space(MSXML, Exml, and I think EasyXML) and nice easy to read formatting. Flash- it seems- decides that each of these white space areas is a node(or more than one) - therefore I can't read the whole XML object the way I have the program designed.
    The new ignoreWhite feature that the developers added....well like some macromedia info - is poorly documented -

    XMLnode.ignoreWhite = true;

    this is my guess as to how this function works- anyone that has got it to work let me know.

    So... looking at an external fix I have only found 1 editor that seems to work with Flash XML - Peter's XML editor, because when it saves XML it removes all of the whitespace for me. However, it's pretty simple and doesn't have as many features as I would hope.
    Does anyone know an editor that works really well with Flash?
    Thanks in Advance-

    -><|TheMadFlasher|><-
    The more Flash I learn.. the more my mind slips away....

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    The xmlobject.ignoreWhite=true value will only work in the very latest version of the flash player. The flash player which the flash editor has built in does not support this value and so the only real true way to test your movies is to publish your movie each time and view it in an html page: F12

    You only have to set this value once for each xml object you create:

    Code:
    myxml=new XML()
    myxml.ignoreWhite=true
    myxml.load("myxmlfile.xml")
    myxml.onLoad=parse
    The only problem is that this wont work with any other version of the flash player and so the only proper way to code your xml parsing is to check for the correct nodeName.

    so if i add this code to the above code:

    Code:
    function parse(loaded){
        if(loaded){
            myxml=myxml.firstChild
            if(myxml.hasChildNodes()){
                var kids=myxml.childNodes
                for(var z=0;z<kids.length;++i){
                    if(kids[z].nodeName != null){
                        //this is not whitespace
                    }
                }
            }
        }
    }
    the flash xml parser sees whitespace as a node, if you check that the nodeName of a node is not blank(null) then you are effectively ignoring whitespace!As whitespace has a nodeName of blank(null)

    If you need more let me know!

  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    56
    I understand the idea-
    I don't think I'll implement it - it seems that the ignoreWhite command is still too unstable(as to having to make sure that it works/ and have the latest player) I'm willing to work with it - but I've already coded all of my XML read functions- and the program works given the current settings.
    What XML editors have you been using? Do you encounter this problem a lot - is there some "codewords" that I should look for in an XML editor that will remove the whitespace from the saved files in the preferences section of the editor(most other readers seem not to care - only flash does -go figure)

    -><|TheMadFlasher|><-

  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    It is up to you to code your xml in such a way that flash can understand it, this is not up to the xml editor!

    I create my xml in notepad by hand as there isnt much to it really!

    Then i create my scripts to cater for the fact that there may or may not be whitespace in my xml document!

    Thats the only real cross-platform,cross-browser solution!

  5. #5
    Junior Member
    Join Date
    Apr 2001
    Posts
    7

    parser should have ignored whitespace automatically

    While these scripts are needed to get the job done, I don't agree that it's up to us "to code your xml in such a way that flash can understand it".

    The fact that the built-in parser doesn't automatically ignore whitespace is just ridiculous. No developer would write XML files without whitespace, so it should be automatic that the parser ignore it.

    And I don't get your "cross-platform, cross-browser solution" comment, either. If the XML files are in plain text (ASCII or Unicode), then they are already cross-platform; therefore, searching for the whitespace in an XML file would have been easy.

    Obviously, one has to pick a solution: write the code to overlook the whitespace or create XML files without it. But I still feel that Flash's parser should have always ignored whitespace.

  6. #6
    Member
    Join Date
    Feb 2001
    Posts
    56
    I have to admit that I had a good laugh when Guru stated that the editor doesn't matter. (No offense at all intended)
    I'm writing 15-30K XML documents that are custom and writing/editing them with Notepad would be true and complete Madness. Let alone having to teach 10 other non-programmers to edit/create these documents without whitespace in notepad.(Still working on creating a working XML editor in Flash) Thankfully I've found an editor that works with Flash 5- (Plug for someone else) Peter's XML editor- when it saves the file it rids it of the whitespace - and when it re-loads it into the editor it puts it back in.
    Unfortunately - I haven't found a way to write my actionscript/XML read functions to consistantly ignore whitespace if it is there or not. I remember seeing in one FLA here that someone had written a function that got rid of whitespace - but I remember trying to get it to work and... well it didn't,I think that it was part of an XML editor.. that I couldn't get to work either. If anyone has gotten function or editor to work from Flash- I'd love to see it.

    To me, IMHO, I agree with Opus, Flash developers should have handled this area already - and have working fix instead of a shoddy one with "ignoreWhite"- which is inconsistant a best.

    -><|TheMadFlasher|><-

  7. #7
    Member
    Join Date
    Jul 2000
    Posts
    75

    Colin Moock comes through again...

    Check out this link:

    http://www.moock.org/webdesign/lectu...p/slide15.html

    It's part of Colin's lecture from FF2001 in San Francisco. A great script to remove whitespace.

    But I think that you should write your Flash to ingore the whitespace, not to rely on the editor. If you start using an XML feed from somewhere else you're screwed if they have whitespace. A good practice to get into.

    Also, my plug for an editor is XML Spy. :)

    -k
    [Edited by fancyk on 04-26-2001 at 04:44 PM]

  8. #8
    Junior Member
    Join Date
    Mar 2000
    Posts
    4
    Ditto. XML spy is the editor of choice.

  9. #9
    Senior Member
    Join Date
    Nov 2000
    Posts
    100

    XML Editors and ignoreWhite

    I'm going to summarize to make sure I've got it.

    If I'm building a Flash file that may be taking XML files from various sources that I'm not in control of I need to write some action script to remove white spaces since I can't be guaranteed that my Flash file won't receive an XML file with white space. The function to remove the white space is:

    function parse(loaded){
    if(loaded){
    myxml=myxml.firstChild
    if(myxml.hasChildNodes()){
    var kids=myxml.childNodes
    for(var z=0;z
    if(kids[z].nodeName != null){
    //this is not whitespace
    }
    }
    }
    }
    }

    If I'm writing a Flash file that will have a total control over the XML files I can then skip this part and try to remove the white space(carriage returns) from my xml.

    Is that right?




  10. #10
    Junior Member
    Join Date
    Mar 2001
    Posts
    20
    Crew -

    I saw you all were having trouble with whitespace... I wrote the following functions to take care of this. The three functions below can be used in different situations. I have noticed that some situations call for different kinds of trims. Many of my XML documents, for some reason, not only have white spaces in them, but also two weird hard return characters at the end. Anyway, try the functions below. They worked out fine for me.



    Code:
    // 
    // =================================================================================================================
    // FUNCTION
    // =================================================================================================================
    // 
    function trim (bobString) {
    	finalString = "";
    	myArray = new Array();
    	myArray = bobString.split(" ");
    	for (i=0; i<myArray.length; i++) {
    		// if that element of the array is bigger than 1, it means it is not a space and is our candidate!
    		if (myArray[i].length>1) {
    			finalString = myArray[i];
    		}
    	}
    	// have to remove two last characters (not spaces -- I don't know what they are!!!"
    	finalString = finalString.slice(0, finalString.length-2);
    	return finalString;
    }
    // 
    // =================================================================================================================
    // FUNCTION
    // =================================================================================================================
    // 
    function trimWithoutTruncate (bobString) {
    	finalString = "";
    	myArray = new Array();
    	myArray = bobString.split(" ");
    	for (i=0; i<myArray.length; i++) {
    		if (myArray[i].length>1) {
    			finalString = myArray[i];
    		}
    	}
    	return finalString;
    }
    // 
    // =================================================================================================================
    // FUNCTION
    // =================================================================================================================
    // 
    function trimForNum (bobString) {
    	finalString = "";
    	for (i=0; i<bobString.length; i++) {
    		// if that element of the array is a number
    		if (bobString.charAt(i) == "1" || bobString.charAt(i) == "2" || bobString.charAt(i) == "3" || bobString.charAt(i) == "4" || bobString.charAt(i) == "5" || bobString.charAt(i) == "6" || bobString.charAt(i) == "7" || bobString.charAt(i) == "8" || bobString.charAt(i) == "9" || bobString.charAt(i) == "0") {
    			finalString = finalString+bobString.charAt(i);
    		}
    	}
    	return finalString;
    }

  11. #11
    Junior Member
    Join Date
    Apr 2001
    Posts
    1

    Post

    Check out this script.
    After stripping all the traces that I used for debugging, the code will take just a few lines...
    <FONT Color="#0066AA">
    <BLOCKQUOTE><HR>
    // Created by Ruslan Vasylyev, ruslan@canada.com

    nLevel = 1;
    xmlData = new XML();
    xmlData.onLoad = parseXML();
    xmlData.load("data.xml");

    function parseXML(loaded){
    if(loaded){
    xmlCleanup(this); // or xmlClenup(xmlData);
    }
    }

    <HR>

    function xmlCleanup (xmlNode) {

    // Created by Ruslan Vasylyev, ruslan@canada.com
    // This script removes whitespaces and empty nodes from XML files
    // commented lines were used to debug the script

    with (xmlNode) {
    //Spaces="";
    //for(i=0;i<nLevel;i++){Spaces+=" "};
    //trace ("["+nLevel+"] "+Spaces+nodeName+":"+nodeValue+"("+nodeType+" )");
    //Spaces+=" ";
    if (firstChild!=null) {
    //trace (Spaces+"firstChild");
    nLevel++;
    if (xmlCleanup(firstChild)) {
    //trace (Spaces+"Removing:"+firstChild.nodeName+":"+firstC hild.nodeValue);
    firstChild.removeNode()
    }
    nLevel--;
    }
    if (nextSibling != null) {
    //trace (Spaces+"nextSibling");
    if (xmlCleanup(nextSibling)) {
    //trace (Spaces+"Removing:"+nextSibling.nodeName+":"+nextS ibling.nodeValue);
    nextSibling.removeNode()
    }
    }
    //trace (Spaces+"Return: "+nodeName == null && nodeType==3);

    return nodeType==3 && nodeValue.indexOf("\r\n")!=-1 && nodeName == null;
    }
    }
    <HR>
    function xmlTree (xmlNode) {

    // This function is used to view the actual XML tree in the debug mode
    // Created by Ruslan Vasylyev, ruslan@canada.com

    with (xmlNode) {
    Spaces="";
    for(i=0;i<nLevel;i++){Spaces+=" "};
    trace ("["+nLevel+"] "+Spaces+nodeName+":"+nodeValue+"("+nodeType+" )");
    Spaces+=" ";
    if (firstChild!=null) {
    nLevel++;
    trace (Spaces+"firstChild");
    xmlTree(firstChild);
    nLevel--;
    }
    if (nextSibling != null) {
    trace (Spaces+"nextSibling");
    xmlTree(nextSibling)
    }
    }
    }
    <HR>
    </BLOCKQUOTE>
    </FONT>
    [Edited by mcbit on 05-17-2001 at 07:18 PM]

  12. #12

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