一、建立XML对象:
var myXML = new XML();
二、援用XML文件:
myXML.load("pro.xml");
三、忽略空格: //默认的为false
myXML.ignoreWhite = true;
四、处理XML对象的函数:
myXML.onLoad = function(success) { statements;}
五、pro.XML文件的内容
<products name="good"><product name="well">wyu</product><product name="better">wyu2</product></products>
六、测试前往值 1、myXML.childNodes[0]将前往:
<products name="good">
<product name="well">wyu</product>
<product name="better">wyu2</product>
</products>
2、myXML.childNodes[0].nodeName将前往:
good
3、myXML.childNodes[0].childNodes[0].name将前往:
well
4、myXML.childNodes[0].childNodes[0]将前往:
<product name="well">
wyu
</product>
5、myXML.childNodes[0].childNodes[0].nodeName将前往:
well
6、myXML.childNodes[0].childNodes[1].attributes.name将前往:
better
7、myXML.childNodes[0].childNodes[0].childNodes[0].nodeValue将前往:
wyu
8、
var myName = myXML.firstChild.firstChild;
trace(myName.nodeName);//将输出well
myName = myName.nextSibling;
trace(myName.nodeName);//将输出better childNodes[0]等价于firstChild
七、测试代码
var myXML = new XML();
myXML.load("pro.xml");
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {
if(success) {
myArray = myXML.childNodes[0];
trace(myArray.attributes.name);
/*trace(myXML.childNodes[0].childNodes[1].firstChild.nodeValue);
trace(myXML.firstChild);
trace(myXML.childNodes[0].nodeName);
trace(myXML.firstChild.attributes.name);
trace(myXML.childNodes[0].childNodes[1].nodeName);
trace(myXML.childNodes[0].childNodes[1].attributes.name);
trace(myXML.firstChild.firstChild);
trace(myXML.firstChild.firstChild.nodeName);
trace(myXML.firstChild.firstChild.attributes.name);
trace(myXML.childNodes[0].childNodes[0].childNodes