XML test
♥0 |
Line 52 |
Modified 2016-07-19 00:01:32 |
MIT License
archived:2017-03-20 01:57:31
ActionScript3 source code
/**
* Copyright Cheshir ( http://wonderfl.net/user/Cheshir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cNfL
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var tf:TextField;
public function FlashTest() {
// write as3 code here..
var cond:XML =
<conditions>
<not>
<and>
<unit_level_gt level="4"/>
<unit_update_gt id="spider_poison"/>
</and>
</not>
<or>
<user_level_gt level="3"/>
<user_building_gt building="den_of_spiders" level="2"/>
</or>
</conditions>;
tf = new TextField();
tf.autoSize = 'left';
tf.x = 50; tf.y = 50;
addChild(tf);
var need:Boolean = true;
var iter:Array = [0];
var parse:XML = cond;
try {
sayXML(cond.child(iter[0])); // correct up level
iter[1] = 0; // is up level...
sayXML(cond.child(iter[0]).child(0));
sayXML(cond.child(iter[0]).child(0).child(0));
// sayXML(cond.child(iter[0]).child(0).child(0).child(0)); error => down level and ++iterate
sayXML(cond.child(iter[0]).child(0).child(1));
// sayXML(cond.child(0).child(0).child(2)); error
// sayXML(cond.child(0).child(1)); error
sayXML(cond.child(1));
sayXML(cond.child(1).child(0));
// sayXML(cond.child(1).child(0).child(0)); error
sayXML(cond.child(1).child(1));
// sayXML(cond.shild(1).child(1).child(0)); error
// sayXML(cond.child(1).child(2)); error
// sayXML(cond.child(2)); error last
// end;
} catch(error:Error){
sayXML(<error/>);
}
// I LOVE XML*
}
public function sayXML(xml:*):void{
var t:String = '';
if(xml is XML){
t = 'xml';
} else if(xml is XMLList){
t = 'xmllist';
} else {
tf.appendText('\n void');
}
tf.appendText('\n=========== '+t+'\n'+xml.name());
}
}
}
// *sarcasm