xml replace whitespace example for stackoverflow
♥0 |
Line 40 |
Modified 2011-02-04 03:15:12 |
MIT License
archived:2017-03-20 04:32:07
ActionScript3 source code
/**
* Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/naqG
*/
package {
/**
* ...
* @author www0z0k
*/
import flash.text.TextField;
import flash.display.Sprite;
import flash.text.TextFieldAutoSize;
public class FlashTest extends Sprite {
private var tf:TextField;
private var targetNodeName: String = 'w';
private var toReplace: String = ' ';
private var replaceWith:String = '%SPACE%';
public function FlashTest() {
tf = new TextField();
addChild(tf);
tf.multiline = true;
tf.autoSize = TextFieldAutoSize.LEFT;
var srcStr:String = '<?xml version="1.0" encoding="utf-8" ?>\n<data>\n' +
' <w> </w>\n' +
' <w> Test</w>\n' +
' <w>Test </w>\n' +
' <oneMoreNode>\n' +
' <w> </w>\n' +
' <w> ololo </w>\n' +
' <w>ololo </w>\n' +
' </oneMoreNode>\n' +
'</data>';
XML.ignoreWhitespace = false;
XML.prettyPrinting = false;
var xml:XML = new XML(srcStr);
tf.appendText('raw xml:\n' + xml);
for (var i:int = 0; i < /*xml..w*/xml.descendants(targetNodeName).length(); i++ ) {
while((/*xml..w*/xml.descendants(targetNodeName)[i] + '').indexOf(toReplace) != -1){
/*xml..w*/xml.descendants(targetNodeName)[i] = (/*xml..w*/xml.descendants(targetNodeName)[i] + '').replace(toReplace, replaceWith);
}
}
tf.appendText('\n\nmodofied xml:\n' + xml);
}
}
}