文章詳情頁(yè)
讀寫xml文件的2個(gè)小函數(shù)
瀏覽:5日期: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配置jdk的操作方法2. django 鏈接多個(gè)數(shù)據(jù)庫(kù) 并使用原生sql實(shí)現(xiàn)3. IDEA插件EasyCode及MyBatis最優(yōu)配置步驟詳解4. Django程序的優(yōu)化技巧5. XML入門的常見(jiàn)問(wèn)題(一)6. Python多線程操作之互斥鎖、遞歸鎖、信號(hào)量、事件實(shí)例詳解7. IntelliJ IDEA設(shè)置自動(dòng)提示功能快捷鍵的方法8. Python常用GUI框架原理解析匯總9. idea給項(xiàng)目打war包的方法步驟10. idea修改背景顏色樣式的方法
排行榜
