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