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);
}
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();
}