一、文件内容
<funds>
<fund>
<name>中银中国</name>
<lot>274</lot>
<net>1.6612</net>
</fund>
<fund>
<name>广发稳健</name>
<lot>280.85</lot>
<net>1.5942</net>
</fund>
</funds>
二、源码
private var filePath:String = null;
private var xmlList:XMLList = null;
private function openConfig():void{
var file:File = new File();
file.browseForOpen("选择文件", [new FileFilter("*.xml","*.xml")]);
file.addEventListener(Event.SELECT, onFileSelect);
}
private function onFileSelect(e:Event):void{
//读文件
var fs:FileStream = new FileStream();
fs.open(File(e.target), FileMode.READ);
var txt:String = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
filePath = File(e.target).nativePath; //文件路径
xmlList = new XMLList(txt); //文件内容
//获取节点值
lot1.text = xmlList.children()[0].lot;
netValue1.text = xmlList.children()[0].net;
lot2.text = xmlList.children()[1].lot;
netValue2.text = xmlList.children()[1].net;
}
private function saveConfig():void{
//设置节点值
xmlList.children()[0].lot = lot1.text;
xmlList.children()[0].net = netValue1.text;
xmlList.children()[1].lot = lot2.text;
xmlList.children()[1].net = netValue2.text;
//写文件
var fs:FileStream = new FileStream();
fs.open(new File(filePath), FileMode.WRITE);
fs.writeUTFBytes(xmlList.toXMLString());
fs.close();
}
本文介绍了一个使用ActionScript编写的简单程序,该程序能够打开并读取XML文件中的基金数据,包括基金名称、份额及净值,并允许修改这些数据后保存回原文件。

712

被折叠的 条评论
为什么被折叠?



