Actionscript 3 - How can i convert from XMLList to XML?

流过昼夜 提交于 2019-12-11 05:43:42

问题


My function is returning XML, so i do:

return xml.blah.blah.blah

It tells me it can't convert XMLList to XML

so i'm guessing xml.blah.blah.blah is a XMLList.

How can i do this (convert XMLList to XML)? the simpliest way possible?


回答1:


You should be able to just cast the XMLList to XML.
Either:

XML(xml.blah.blah)

or

(xml.blah.blah as XML)



回答2:


You can access items of an XMLList like you would an array:

var booksXML:XML =
<Books>
    <Book ISBN="0000000000">
        <title>Title 1</title>
        <author>Author 1</author>
    </Book>
    <Book ISBN="1111111111">
        <title>Title 2</title>
        <author>Author 2</author>
    </Book>
    <Book ISBN="2222222222">
        <title>Title 3</title>
        <author>Author 3</author>
    </Book>
    <Book ISBN="3333333333">
        <title>Title 4</title>
        <author>Author 4</author>
    </Book>
</Books>;


var authorList:XMLList = booksXML.Book.author;

for (var i:int = 0; i < authorList.length(); i++)
{
    var authorElement:XML = authorList[i];
    trace(authorElement);
}


来源:https://stackoverflow.com/questions/8458469/actionscript-3-how-can-i-convert-from-xmllist-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!