首页 > 代码库 > XML字符串解析实体类方法
XML字符串解析实体类方法
/// <summary> /// XML字符串解析实体类方法 /// </summary> public class StringXML { public StringXML() { } public StringXML(string ver, string node) { this.version = int.Parse(ver); this.nodeText = int.Parse(node); } /// <summary> /// XML版本号 /// </summary> public int version { get; set; } /// <summary> /// 节点Text /// </summary> public int nodeText { get; set; } /// <summary> /// 字段内容转化成xml格式字符串 /// </summary> /// <param name="ver"></param> /// <param name="node"></param> /// <returns></returns> public static string ConvertToXMLStr(string ver, string node) { XmlDocument xmlDoc = new XmlDocument(); XmlElement version = xmlDoc.CreateElement("version"); version.InnerText = ver; xmlDoc.AppendChild(version); XmlElement nodeText = xmlDoc.CreateElement("nodeText"); nodeText.InnerText = node; xmlDoc.AppendChild(nodeText); return xmlDoc.OuterXml; } /// <summary> /// XML字符串解析成实体类对象 /// </summary> /// <param name="str"></param> /// <returns></returns> public StringXML AnalysisXmlStr(string str) { StringXML strXML = new StringXML(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(str); XmlNodeList nodeList = xmlDoc.ChildNodes; foreach (XmlNode node in nodeList) { if (node.Name == "version") { strXML.version = int.Parse(node.InnerText); } else if(node.Name == "nodeText") { strXML.nodeText = int.Parse(node.InnerText); } } return strXML; } }
XML字符串解析实体类方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。