主题:  XML.stripsWhite()

Demon.S

职务:版主
等级:5
金币:10.0
发贴:2468
#12002/1/1 13:50:23
i have a good function to figure out white space with xml.ingorewhite,post here:

//from Demon.S function lib
// Strips whitespace nodes from an XML document
// by passing twice through each level in the tree
XML.prototype.stripsWhite=stripsWhite;
function stripsWhite (XMLnode) {
    // Loop through all the children of XMLnode
    for (var i = 0; i        // If the current node is a text node...
        if (XMLnode.childNodes[i].nodeType == 3) {
            // ...check for any useful characters in the node.
            var j = 0;
            var emptyNode = true;
            for (j=0; j                // A useful character is anything over 32 (space, tab,
                // new line, etc are all below).
                if (XMLnode.childNodes[i].nodevalue.charCodeAt(j)>32) {
                    emptyNode = false;
                    break;
                }
            }
            // If no useful charaters were found, delete the node.
            if (emptyNode) {
                XMLnode.childNodes[i].removeNode();
            }
        }
    }
    // Now that all the whitespace nodes have been removed from XMLnode,
    // call stripWhitespaceDoublePass on its remaining children.
    for (var k = 0; k        ignoreWhite(XMLnode.childNodes[k]);
    }
}


DS



5D荣誉斑竹

职务:普通成员
等级:2
金币:2.0
发贴:617
#22002/1/1 21:03:40
谢谢画魔兄!虽然现在用不到,但相信很快就会用到的!