标签:style blog color os 文件 2014
<?xml version="1.0" encoding="utf-8"?> <userInfo> <userName>sa</userName> <userPwd>111111</userPwd> </userInfo>
// *********************************************************************** // Assembly : XML操作 // Author : Amy // Created : 02-17-2014 // // Last Modified By : Amy // Last Modified On : 02-17-2014 // *********************************************************************** // <copyright file="MUserInfo.cs" company="Microsoft"> // Copyright (c) Microsoft. All rights reserved. // </copyright> // <summary></summary> // *********************************************************************** namespace XML操作 { /// <summary> /// Class MUserInfo. /// </summary> public class MUserInfo { /// <summary> /// The user name /// </summary> private string userName = string.Empty; /// <summary> /// The user password /// </summary> private string userPwd = string.Empty; /// <summary> /// Gets or sets the name of the user. /// </summary> /// <value>The name of the user.</value> public string UserName { get { return userName; } set { userName = value; } } /// <summary> /// Gets or sets the user password. /// </summary> /// <value>The user password.</value> public string UserPwd { get { return userPwd; } set { userPwd = value; } } } }
// *********************************************************************** // Assembly : XML操作 // Author : Amy // Created : 02-17-2014 // // Last Modified By : Amy // Last Modified On : 02-18-2014 // *********************************************************************** // <copyright file="XMLOperate.cs" company="Microsoft"> // Copyright (c) Microsoft. All rights reserved. // </copyright> // <summary></summary> // *********************************************************************** using System.Xml; namespace XML操作 { /// <summary> /// Class XMLOperate. /// </summary> public class XMLOperate { /// <summary> /// Loads the XML. /// </summary> /// <param name="xmlfileName">Name of the xmlfile.</param> /// <returns>System.String.</returns> public static string LoadXML(string xmlfileName) { string result = string.Empty; XmlDocument xml = new XmlDocument(); xml.Load(@xmlfileName); return xml.InnerXml.ToString(); } /// <summary> /// Saves the XML. /// </summary> /// <param name="xmlContent">Content of the XML.</param> /// <param name="xmlFileName">Name of the XML file.</param> public static void SaveXML(string xmlContent, string xmlFileName) { XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlContent); xml.Save(@xmlFileName); } /// <summary> /// Gets the user information by executable ml. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>MUserInfo.</returns> public static MUserInfo GetUserInfoByXMl(string fileName) { MUserInfo model = new MUserInfo(); XmlDocument xml = new XmlDocument(); xml.Load(@fileName); XmlNode xmlUserName = xml.SelectSingleNode("userInfo/userName"); if (xmlUserName != null) { model.UserName = xmlUserName.InnerText.Trim(); } XmlNode xmlUserPwd = xml.SelectSingleNode("userInfo/userPwd"); if (xmlUserPwd != null) { model.UserPwd = xmlUserPwd.InnerText.Trim(); } return model; } /// <summary> /// Sets the user information automatic XML. /// </summary> /// <param name="flieName">Name of the flie.</param> /// <param name="model">The model.</param> public static void SetUserInfoToXML(string flieName, MUserInfo model) { XmlDocument xml = new XmlDocument(); xml.Load(@flieName); XmlNode xmlUserName = xml.SelectSingleNode("userInfo/userName"); if (xmlUserName != null) { xmlUserName.InnerText = model.UserName; } XmlNode xmlUserPwd = xml.SelectSingleNode("userInfo/userPwd"); if (xmlUserPwd != null) { xmlUserPwd.InnerText = model.UserPwd; } xml.Save(@flieName); } } }
标签:style blog color os 文件 2014
原文地址:http://www.cnblogs.com/tianxue/p/3854037.html