首页 > 开发 > Flex > 正文

Flex 读取xml文件的方法

2024-09-12 17:51:27
字体:
来源:转载
供稿:网友
方法一:
复制代码 代码如下:

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();
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表