xml和xmllist最大的区别就是是否含有根节点。
典型的XML,<root>是根节点,<node>是子节点,type是属性名:
<root> <node type="boy" id="01" name="lucy"/> <node type="boy" id="01" name="jim"/> <node type="boy" id="01" name="kate"/> <event time="1" parent="01" description="事件1"/> <event time="2" parent="02" description="事件2"/> </root>
<node type="boy" id="01" name="lucy"/> <node type="boy" id="01" name="jim"/> <node type="boy" id="01" name="kate"/> <event time="1" parent="01" description="事件1"/> <event time="2" parent="02" description="事件2"/>
1、用as创建xml:
第一种方法:
var myXML:XML = <root> <node type="boy" id="01" name="lucy"/> <node type="boy" id="01" name="jim"/> <node type="boy" id="01" name="kate"/> <event time="1" parent="01" description="事件1"/> <event time="2" parent="02" description="事件2"/> </root> trace(myXML); var myXML2:XML = <root> <node type="boy" id="01" name="gary"/> </root> var myXML3:XML = <root> <node type="boy" id="01" name="gary">hello</node> </root> var myXML4:XML = <root> <node type="boy" id="01" name="gary"> <child id="02"/> </node> </root>
第二种方法:
var str:String = "<root>" + "<node type='boy' id='01' name='lucy'/>" + "<node type='boy' id='01' name='jim'/>" + "<node type='boy' id='01' name='kate'/>" + "</root>"; var myXML:XML = new XML(str); trace(myXML);
2、 输出XML某一类节点: