ࡱ> Root Entryp|YrRASHp wContents'RPage 1i !"#$%&()*+,-./0Root Entryp|YrRASH^ContentsRPage 1y 1CPicPage CPicLayer CPicFrameCPicText {$Wl @TArial3f3n"for(i in doc.firstChild. attributes) {trace(i + ": " +doc.firstChild.attributes[i]); CPicShape $"8@Arial"P  f̙^;//q0B/q//q/0p Bq//0H _8@Arial"xmlDoc '8@Arial"#textf̙U0030 030|3 000303( 063 I0 00 []3f3nU"00hQ0J $0@Arial"xml object code sample ̘U"00hQ0J Hn 6u@Arial3f3n" 3f3(Zh88r8*88"0U00`8p? backgroundOO dC*@@Arial"this is a code demo showing how to strip empty whitespace nodes from an xml object. view the code on the first frame of the scripts layer. export the movie and watch the output window to see the results of the trace statements in the code...?c contentOO? // make an xml doc with whitespace. externally loaded docs very often have lots of whitespace between tags doc = new XML(' ActionScript: The Definitive Guide' + 'Colin Moock ' + 'O\'reilly & Associates, Inc '); // let's see what our doc looks like before we remove the whitespace nodes trace("\n-------------before empty node strip------------------"); trace(doc); // see below for two different whitespace stripping functions. the function // stripWhitespaceDoublePass is faster than stripWhitespaceTraverse in the // flash 5 player because Array.concat() is slow. stripWhitespaceDoublePass(doc); // uncomment the following line to try the other function. // stripWhitespaceTraverse (doc); // all clean! let's look at the new version trace("\n-------------after empty node strip------------------"); trace(doc); // Function: stripWhitespaceTraverse() // Version: 1.0.1 // Desc: Strips whitespace nodes from an // XML document by traversing the tree function stripWhitespaceTraverse (XMLnode) { // Create a list of nodes to process var nodeList = new Array(); // Seed the list with the node passed to the function nodeList[0] = XMLnode; // Create a local variable to track whether we've // found an empty node. var emptyNode; // Local counter variable. var i = 0; // Process the passed node and its descendents until // there are none left to process while (nodeList.length > 0) { // Grab the first node on the list, and remove it from the list currentNode = nodeList.shift(); // Assume we're dealing with a non-empty node. emptyNode = false; // If this node has children... if (currentNode.childNodes.length > 0) { // ...add this node's children to the list of nodes to process nodeList = nodeList.concat(currentNode.childNodes); } else { // ...otherwise, this node is the end of a branch, so check if it's a // text node... if (currentNode.nodeType == 3) { // Yup, it's a text node, so check if it only contains empty whitespace. // Assume it's only whitespace and try to prove the assumption wrong. emptyNode = true; for(i = 0; i < currentNode.nodeValue.length; i++) { // A useful character is anything over 32 (space, // tab, new line, etc are all below). if(currentNode.nodeValue.charCodeAt(i) > 32) { emptyNode = false; break; } } } // If no useful charaters were found, delete the node if(emptyNode) { currentNode.removeNode(); } } } } // Strips whitespace nodes from an XML document // by passing twice through each level in the tree function stripWhitespaceDoublePass(XMLnode) { // Loop through all the children of XMLnode for (var i = 0; i < XMLnode.childNodes.length; 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 < XMLnode.childNodes[i].nodeValue.length; 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 < XMLnode.childNodes.length; k++) { stripWhitespaceDoublePass(XMLnode.childNodes[k]); } } scriptsO} =*@hhhhh33 Vector::Template0"PublishFormatProperties::generator CColorDef3PfP0PHP`Px3) CDocumentPagePage 1Scene 19  =*@hhhhh33 Vector::Template0"PublishFormatProperties::generator CColorDef3PfP0PHP`Px333(3f<03CH3F`3Hxf0f30ff(0f5Hf<`f@x3330333xf3d03]H3Z`3Xx3333303f3PPH33Px`33Px33Pf30f33PHff3(PHf3<x`f3Cxf3Ffff`f03f0ffx0fkHfd`f`x3f033fPH3ffxPH3fdx`3f]x3fZff0f3fPHfff`ffP0xffPxffPH3HfHxH̙n`hx3H33x`3fx`3xx`3̙kx3dfHf3x`ff0xfx0xf̙dxf]`3`f``x`px3`33x3fx3x3xx3nf`f3xffxfxfxxfkx3xfxxxxx3x333f333xfxf3fffffxxH3 HfH(H2`8x`3 `f`̙`(`0xx3xfxx x(xPx3H33x`f3x`3(x`35x3<3`33xf3 x̙3x3(x323x33f3 333(xfH3fx`ff0xf(0xf<xfCf`3fxffx̙fxf(xf5fx3ffff ff((xH3x`f0x̙PPP`3xfx̙P̙(P<x3f̙(xx`3xfxPxPd`3xfx̙PPx3f(xx3fxx3f̙xx3f3f3nPPHf`zf*]x CPicPage CPicLayer CPicFrameCPicText {$Wl @TArial3f3n"for(i in doc.firstChild. attributes) {trace(i + ": " +doc.firstChild.attributes[i]); CPicShape $"8@Arial"P  f̙^;//q0B/q//q/0p Bq//0H _8@Arial"xmlDoc '8@Arial"#textf̙U0030 030|3 000303( 063 I0 00 []3f3nU"00hQ0J $0@Arial"xml object code sample ̘U"00hQ0J Hn 6u@Arial3f3n" 3f3(Zh88r8*88"0U00`8p? backgroundOO dC*@@Arial"this is a code demo showing how to strip empty whitespace nodes from an xml object. view the code on the first frame of the scripts layer. export the movie and watch the output window to see the results of the trace statements in the code...?c contentOO? // make an xml doc with whitespace. externally loaded docs very often have lots of whitespace between tags doc = new XML(' ActionScript: The Definitive Guide' + 'Colin Moock ' + 'O\'reilly & Associates, Inc '); // let's see what our doc looks like before we remove the whitespace nodes trace("\n-------------before empty node strip------------------"); trace(doc); // see below for two different whitespace stripping functions. the function // stripWhitespaceDoublePass is faster than stripWhitespaceTraverse in the // flash 5 player because Array.concat() is slow. stripWhitespaceDoublePass(doc); // uncomment the following line to try the other function. // stripWhitespaceTraverse (doc); // all clean! let's look at the new version trace("\n-------------after empty node strip------------------"); trace(doc); // Function: stripWhitespaceTraverse() // Version: 1.0.1 // Desc: Strips whitespace nodes from an // XML document by traversing the tree function stripWhitespaceTraverse (XMLnode) { // Create a list of nodes to process var nodeList = new Array(); // Seed the list with the node passed to the function nodeList[0] = XMLnode; // Create a local variable to track whether we've // found an empty node. var emptyNode; // Local counter variable. var i = 0; // Process the passed node and its descendents until // there are none left to process while (nodeList.length > 0) { // Grab the first node on the list, and remove it from the list currentNode = nodeList.shift(); // Assume we're dealing with a non-empty node. emptyNode = false; // If this node has children... if (currentNode.childNodes.length > 0) { // ...add this node's children to the list of nodes to process nodeList = nodeList.concat(currentNode.childNodes); } else { // ...otherwise, this node is the end of a branch, so check if it's a // text node... if (currentNode.nodeType == 3) { // Yup, it's a text node, so check if it only contains empty whitespace. // Assume it's only whitespace and try to prove the assumption wrong. emptyNode = true; for(i = 0; i < currentNode.nodeValue.length; i++) { // A useful character is anything over 32 (space, // tab, new line, etc are all below). if(currentNode.nodeValue.charCodeAt(i) > 32) { emptyNode = false; break; } } } // If no useful charaters were found, delete the node if(emptyNode) { currentNode.removeNode(); } } } } // Strips whitespace nodes from an XML document // by passing twice through each level in the tree function stripWhitespaceDoublePass(XMLnode) { // Loop through all the children of XMLnode for (var i = 0; i < XMLnode.childNodes.length; 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 < XMLnode.childNodes[i].nodeValue.length; 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 < XMLnode.childNodes.length; k++) { stripWhitespaceDoublePass(XMLnode.childNodes[k]); } } scriptsO*@hhhhh33 Vector::Template0"PublishFormatProperties::generator CColorDef3PfP0PHP`Px3) CDocumentPagePage 1Scene 19  =*@hhhhh33 Vector::Template0"PublishFormatProperties::generator CColorDef3PfP0PHP`Px333(3f<03CH3F`3Hxf0f30ff(0f5Hf<`f@x3330333xf3d03]H3Z`3Xx3333303f3PPH33Px`33Px33Pf30f33PHff3(PHf3<x`f3Cxf3Ffff`f03f0ffx0fkHfd`f`x3f033fPH3ffxPH3fdx`3f]x3fZff0f3fPHfff`ffP0xffPxffPH3HfHxH̙n`hx3H33x`3fx`3xx`3̙kx3dfHf3x`ff0xfx0xf̙dxf]`3`f``x`px3`33x3fx3x3xx3nf`f3xffxfxfxxfkx3xfxxxxx3x333f333xfxf3fffffxxH3 HfH(H2`8x`3 `f`̙`(`0xx3xfxx x(xPx3H33x`f3x`3(x`35x3<3`33xf3 x̙3x3(x323x33f3 333(xfH3fx`ff0xf(0xf<xfCf`3fxffx̙fxf(xf5fx3ffff ff((xH3x`f0x̙PPP`3xfx̙P̙(P<x3f̙(xx`3xfxPxPd`3xfx̙PPx3f(xx3fxx3f̙xx3f3f3nPPHf`zf*]x h