Flex

关注公众号 jb51net

关闭
首页 > 网页制作 > Flash > Flex > Flex 读取xml

Flex 读取xml文件的方法

作者:

Flex 读取xml文件的多种方法小结,大家可以根据需要自己选择。
方法一:
复制代码 代码如下:

private function readxml1():void{
var xmlfile:file = new file("file path");
var stream:filestream = new filestream();
stream.open(xmlfile, filemode.read);
var xml:xml = xml(stream.readutfbytes(stream.bytesavailable));
stream.close();
}

方法二:
复制代码 代码如下:

private function readxml2():void{
var urlrequest:urlrequest = new urlrequest("xml file path");
var urlloader:urlloader = new urlloader(urlrequest);
urlloader.addeventlistener(event.complete,completehandler);
}

private function completehandler(event:event):void{
var xml:xml = new xml(event.target.data);
trace(xml);
}

flex写xml的方法:
复制代码 代码如下:

public static function writexmlfile(xml:xml):void{
var stream:filestream = new filestream();
var xmlfile:file = new file("file path");
var outputstring:string = '\n';
outputstring += xml.toxmlstring();
outputstring = outputstring.replace(/\n/g, file.lineending);
stream = new filestream();
stream.open(xmlfile, filemode.write);
stream.writeutfbytes(outputstring);
stream.close();
}
阅读全文