问题
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