文章詳情頁(yè)
讀寫xml文件的2個(gè)小函數(shù)
瀏覽:6日期:2022-06-04 09:30:06
要利用DOM 來(lái)存取XML 文件,你必須將XML 文件連結(jié)到HTML 網(wǎng)頁(yè)上。
#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. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟2. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐3. XML入門的常見(jiàn)問(wèn)題(一)4. jsp EL表達(dá)式詳解5. IntelliJ IDEA 統(tǒng)一設(shè)置編碼為utf-8編碼的實(shí)現(xiàn)6. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子7. idea修改背景顏色樣式的方法8. chat.asp聊天程序的編寫方法9. IntelliJ IDEA設(shè)置自動(dòng)提示功能快捷鍵的方法10. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
排行榜
