您的位置:首页 > 编程语言 > C#

c#与flash文件间的xml数据交换

2009-08-24 16:11 344 查看
很简单的程序,c#写入xml文件,flash读取xml数据展示

flash代码-----------------------------------------------------

onClipEvent (load) {
/*读取xml文件,并存到数组myList中*/
System.useCodepage = true;
var doc:XML = new XML();
var myList:Array = new Array();//预先建立一个数组对象用来放置XML节点数据,以便FLASH其他位置的代码都能够访问
doc.load("sys.xml");
doc.ignoreWhite = true;
doc.onLoad = function(success){
if(success){
myList = doc.childNodes[0].childNodes;//当XML加载成功后对上文的myList数组对象进行赋值.
}
total = myList[0].attributes.total;
}
}
onClipEvent (enterFrame) {

loaded = myList[0].attributes.code;
text=string(loaded/total*100).substr(0,5)+"%";
percent = int(loaded/total*100)+1;
yea1 = myList[0].attributes.year1;
yea2 = myList[0].attributes.year2;
string=myList[0].attributes.string;
gotoAndStop(percent);

}

C#代码
using System.Xml;

private void readXml()
{
DataTable  tb=yourtb
try
{
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("shopsys.xml");
XmlNode node = xmlDoc.SelectSingleNode("root");
XmlElement fktxe=(XmlElement)node.SelectSingleNode("fkt");
fktxe.SetAttribute("name","标志1");
fktxe.SetAttribute("total","100");
fktxe.SetAttribute("code","60");
fktxe.SetAttribute("year1","2006");
fktxe.SetAttribute("year2","2008");
fktxe.SetAttribute("string","你已经完成了多少多少");
XmlElement fllxe=(XmlElement)node.SelectSingleNode("fll");
fllxe.SetAttribute("name","标志2");
fllxe.SetAttribute("total","100");
fllxe.SetAttribute("code","80");
fllxe.SetAttribute("year1","2009");
fllxe.SetAttribute("year2","2010");
fllxe.SetAttribute("string","你已经完成了多少多少");
xmlDoc.Save("sys.xml");
}
catch
{

return;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: