Flex 读写xml文件的方法_Flex
来源:互联网 发布:lvs和nginx的区别 编辑:程序博客网 时间:2024/04/30 19:40
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 = '<?xml version="1.0" encoding="utf-8"?>\n';outputString += xml.toXMLString();outputString = outputString.replace(/\n/g, File.lineEnding);stream = new FileStream();stream.open(xmlFile, FileMode.WRITE);stream.writeUTFBytes(outputString);stream.close();}
补充:可以通过WebService,HttpService以及RemoteObject等方式调用Java或C#等完成文件的读写操作。
Flex端:
<mx:Script>javaService.getOutStream(xml);</mx:Script><mx:RemoteObject id="javaService" destination="fileOutput" showBusyCursor="true"result="Alert.show('设置成功,请刷新浏览器!')" fault="Alert.show('文件输出错误!')"/>
Java端:
package util;import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;import java.io.OutputStreamWriter;public class setView {public boolean getOutStream(String str) {try {File f = new File("webapps/test/xml/example.xml");FileOutputStream fos = new FileOutputStream(f, false);OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");BufferedWriter bw = new BufferedWriter(osw);bw.write(str);bw.close();osw.close();fos.close();return true;} catch (Exception e) {e.printStackTrace();return false;}}}
config.xml添加配置
<destination id="fileOutput" channels="my-amf"><properties><source>util.setView</source></properties></destination>#Flex
0 0
- Flex 读写xml文件的方法_Flex
- Flex读写XML文件
- xml文件的读写 方法
- Flex的XML读写
- XML文件读写方法
- Flex 读取xml文件的方法:
- java读写xml文件的方法
- 读写XML文件的最简单方法
- java读写xml文件的方法
- java读写xml文件的方法
- PYTHON读写xml文件的方法
- C#读写xml文件的常用方法
- C#读写xml文件的常用方法
- C#读写xml文件的常用方法
- C#读写xml文件的常用方法
- xml文件的读写
- xml文件的读写
- xml文件的读写
- Clover
- android Suspicious method call; should probably call "draw" rather than "onDraw"
- uva 10755 - Garbage Heap(最大和问题)
- HBase设计与开发性能优化
- 书本例子strindex函数
- Flex 读写xml文件的方法_Flex
- poj2923 状压记忆化搜索
- 第四届(2013年十月)福建省大学生程序设计竞赛
- Android xml资源文件中@、@android:type、@*、?、@+含义和区别
- Configuring Automatic Debugging
- 右序strindex函数
- synchronized 同步锁
- 书上例子-简单的atof函数
- POJ 1270 Following Orders 拓扑排序