ActionScript 3.0将XML格式转换为String

时间:2013-04-11 07:56:03

标签: xml actionscript

对不起这里的新手。

这是我的代码:

var xmlLoader:URLLoader =  new URLLoader();
xmlLoader.load(new URLRequest("faculty_data.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
                                               function xmlLoaded(event:Event):void
{   
var xml:XML = XML(event.target.data);

var result1:String = xml.faculty.(@Wordlookup.match(/Sanchez/)).college.toString();
trace(result1); 
trace output ---> <college>COB</college>
             ---> <college>COE</college>

但我想要这样的输出: COB COE

希望有人可以帮助我......我确实尝试过谷歌......

抱歉,这是我的XML

     <facultylist> 
    <faculty Wordlookup="Maria Rosario"> 
        <id>1</id> 
        <fullName>Maria Rosario</fullName> 
        <college>CED </college>
        <department>ELMD</department>
    </faculty> 
   <faculty Wordlookup="Liza Sanchez"> 
        <id>2</id>   
        <fullName>Lysa Sanchez</fullName>  
        <college>CED </college>
        <department>Marketing</department>
    </faculty> 
   <faculty Wordlookup="Melany Sanchez"> 
        <id>3</id>     
        <fullName>Melany Sanchez</fullName>
        <college>CLA </college>
        <department>Marketing</department>
    </faculty> 
</facultylist>

1 个答案:

答案 0 :(得分:0)

我不知道你的XML是怎样的,但我认为你也过滤了@Wordlookup ==“Sanchez”。

请你试试这个:

var xmlLoader:URLLoader =  new URLLoader();
xmlLoader.load(new URLRequest("faculty_data.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{   
    var xml:XML = XML(event.target.data);

    var lstXML:XMLList = xml.faculty.(@Wordlookup.match(/Sanchez/)).college;

    for each(var child:XML in lstXML)
    {
        trace(String(child));
    }
}