Flex 读取xml文件的方法
更新时间:2009年08月09日 00:46:36 作者:
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();
}
复制代码 代码如下:
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();
}
相关文章
使用asx3m与xstream配合解决flex与java利用httpservice传递xml数据问题
过年期间抽空在弄flex前端对象与后端java对象利用httpservice交互的问题。比如前端需要user list数据,构造了flex user object类。2009-02-02Flex中让鼠标移至AdvancedDataGrid的行上不自动修改显示效果
公司项目中出于性能考虑,把mx:Repeater控件换成了mx:AdvancedDataGrid控件来显示。2009-05-05让Flex Builder 3.0与Eclipse3.4整合起来
Flex Builder 3.0 For Eclipse 3.3 安装方法2009-02-02Flex Gumbo 通过textJustify样式设置TextBox文字对齐的例子
接下来的例子演示了Flex Gumbo中如何通过textJustify样式,设置TextBox文字对齐。2009-06-06
最新评论