XML如何序列化成字符串

发布时间:2016-12-8 19:59:11 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"XML如何序列化成字符串",主要涉及到XML如何序列化成字符串方面的内容,对于XML如何序列化成字符串感兴趣的同学可以参考一下。

XML如何序列化成字符串  ----------------------------- using System;using System.Xml.Serialization; namespace BLL.FrameWork{ /// <summary> /// ActionMapping对Struts-config.xml的映射 的摘要说明。 /// 2005-12-11 PM 17:15 Modify HHD. /// </summary> [XmlRoot("action-mappings")] public class ActionMapping {  [XmlElement("action")]   public Action[] Actions; }  public class Action {  [XmlAttribute("name")]  public string Name = "";  [XmlAttribute("classname")]  public string ClassName = "";  [XmlAttribute("path")]  public string Path = "";  [XmlAttribute("input")]  public string Input = "";  [XmlAttribute("validate",DataType="boolean")]  public bool Validate = false;  [XmlAttribute("istransaction",DataType="boolean")]  public bool IsTransAction = false;  [XmlElement("forward")]  public Forward[] Forwords; }  public class Forward {  [XmlAttribute("name")]  public string Name = "";  [XmlAttribute("path")]  public string Path = ""; }} 调用 。。。 Hashtable StrutsData = (Hashtable)HttpContext.Current.Cache["StrutsData"];    if(StrutsData==null)    {     StrutsData = new Hashtable();     string xmlpath = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["strutsconfig"]);     XmlSerializer xs = new XmlSerializer(typeof(ActionMapping));     FileStream fs = new FileStream(xmlpath,FileMode.Open);     ActionMapping actionmapping = (ActionMapping)xs.Deserialize(fs);     fs.Close();     int actionmappinglength = actionmapping.Actions.Length;          for(i=0;i<actionmappinglength;i++)     {      Hashtable temp = new Hashtable();      temp.Add("ClassName",actionmapping.Actions[i].ClassName);      temp.Add("Path",actionmapping.Actions[i].Path);      temp.Add("Input",actionmapping.Actions[i].Input);            temp.Add("Validate",actionmapping.Actions[i].Validate);      temp.Add("IsTransAction",actionmapping.Actions[i].IsTransAction);      temp.Add("Forwords",actionmapping.Actions[i].Forwords);      StrutsData.Add(Convert.ToString(actionmapping.Actions[i].Name),temp);           }     HttpContext.Current.Cache.Insert("StrutsData",StrutsData);    }。。。

上一篇:RFC
下一篇:volatile——多线程程序员最好的朋友

相关文章

相关评论