文章詳情頁
讀寫xml文件的2個(gè)小函數(shù)
瀏覽:32日期:2022-06-04 09:30:06
要利用DOM 來存取XML 文件,你必須將XML 文件連結(jié)到HTML 網(wǎng)頁上。
#region 讀寫xml文件的2個(gè)小函數(shù),2005 4 2 by hyc
public void SetXmlFileValue(string xmlPath,string AppKey,string AppValue)//寫xmlPath是文件路徑+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("http://appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("http://add[@key="" + AppKey + ""]");
if ( xElem1 != null )
{
xElem1.SetAttribute("value",AppValue);
}
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key",AppKey);
xElem2.SetAttribute("value",AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(xmlPath);
}
public void GetXmlFileValue(string xmlPath,string AppKey,ref string AppValue)//讀xmlPath是文件路徑+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
xNode = xDoc.SelectSingleNode("http://appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("http://add[@key="" + AppKey + ""]");
if ( xElem1 != null )
{
AppValue=xElem1.GetAttribute ("value");
}
else
{
// MessageBox.Show ("There is not any information!");
}
}
#endregion
#region 讀寫xml文件的2個(gè)小函數(shù),2005 4 2 by hyc
public void SetXmlFileValue(string xmlPath,string AppKey,string AppValue)//寫xmlPath是文件路徑+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("http://appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("http://add[@key="" + AppKey + ""]");
if ( xElem1 != null )
{
xElem1.SetAttribute("value",AppValue);
}
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key",AppKey);
xElem2.SetAttribute("value",AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(xmlPath);
}
public void GetXmlFileValue(string xmlPath,string AppKey,ref string AppValue)//讀xmlPath是文件路徑+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
xNode = xDoc.SelectSingleNode("http://appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("http://add[@key="" + AppKey + ""]");
if ( xElem1 != null )
{
AppValue=xElem1.GetAttribute ("value");
}
else
{
// MessageBox.Show ("There is not any information!");
}
}
#endregion
標(biāo)簽:
XML/RSS
相關(guān)文章:
1. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)2. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案3. CSS Hack大全-教你如何區(qū)分出IE6-IE10、FireFox、Chrome、Opera4. HTML DOM setInterval和clearInterval方法案例詳解5. XML入門精解之結(jié)構(gòu)與語法6. css代碼優(yōu)化的12個(gè)技巧7. css進(jìn)階學(xué)習(xí) 選擇符8. 告別AJAX實(shí)現(xiàn)無刷新提交表單9. HTML <!DOCTYPE> 標(biāo)簽10. CSS hack用法案例詳解
排行榜
