2010-12-21 73 views
0

我想解析出nodeName但沒有什麼是返回,我的腳本有什麼問題?解析從XML的XML字符串的動作3

import flash.xml.XMLDocument; 
import flash.xml.XMLNode; 
import flash.xml.XMLNodeType; 

var MaintainXML:XML = 
<letter><to>senocular</to><body>Get a life</body></letter>; 

trace("status"+MaintainXML.status); // traces "0" (No error) 
trace("nodeName" + MaintainXML.firstChild.nodeName); // traces "letter" 
trace("nodeName" + MaintainXML.firstChild.firstChild.nodeName); // traces "to" 
trace("nodeValue"+MaintainXML.firstChild.firstChild.firstChild.nodeValue); // traces 
+0

如何接受的答案。我沒有點擊向上箭頭。還有其他地方嗎?大聲笑不要接受。我現在明白了。複選標記 – NanoHead 2010-12-21 19:40:45

回答

1

你試圖使用你的XML的方法或屬性是不存在的:既不是status,也不firstChild,也不nodeName可用於XML Object。 Flash會將這些調用解釋爲搜索查詢,因此它會查找名爲「status」的子節點, 「firstChild」如

<root> 
    <status /> 
    <firstChild /> 
</root> 

並返回一個空的XMLList,因爲當然它找不到這樣的節點。

此外,您的MaintainXMLs根節點爲<letter>,所以第一個孩子將是<to>

試試這個:

var MaintainXML : XML = <letter><to>senocular</to><body>Get a life</body></letter>; 

trace("nodeName:" + MaintainXML.to.name()); // traces "to" 
trace("nodeValue:" + MaintainXML.to.toString()); // traces "senocular"