xml 充當簡易數據庫

後臺:node

寫入節點htm

public static void Update(string path, string node, string attribute, string value)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode xn = doc.SelectSingleNode(node);
XmlElement xe = (XmlElement)xn;
if (attribute.Equals(""))
xe.InnerText = value;
else
xe.SetAttribute(attribute, value);
doc.Save(path);
}
catch { }
}string

 

Update(patch, "/config/string[@id='id']", "value",TextID.Text.Trim());//更新節點(寫入數據)後臺

讀取節點date

public static string Read(string path, string node, string attribute,string htm)
{
string value = "";
try
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode xn = doc.SelectSingleNode(node);
value = (attribute.Equals("") ? (string.IsNullOrEmpty(htm) ? xn.InnerText : xn.InnerXml) : xn.Attributes[attribute].Value);
}
catch { }
return value;
}im

 

CommonForNate.XmlHelper.Read(patch, "/config/string[@id='id']", "value");//取節點數據數據

相關文章
相關標籤/搜索