讀寫xml文件的2個(gè)小函數(shù)
更新時(shí)間:2006年12月22日 00:00:00 作者:
要利用DOM 來存取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
相關(guān)文章
powerbuilder(pb)中 xml的應(yīng)用一例
powerbuilder中的數(shù)據(jù)窗口真是好的不得了,工作基本上都是圍繞它做,很高效,這幾天項(xiàng)目上需要用導(dǎo)出xml文件,就用pb9(xml導(dǎo)出導(dǎo)入功能是從powerbuilder9.0增加的功能)做了一個(gè)demo以驗(yàn)證可行性2009-06-06Xml簡(jiǎn)介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
XML 只是基于普通文本,但卻提供了幾乎可以在任何兩個(gè)應(yīng)用程序間共享數(shù)據(jù)的方式2017-08-08xpath簡(jiǎn)介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
xpath就是選擇XML文件中節(jié)點(diǎn)的方法。下面通過本文給大家分享xpath的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2017-08-08一個(gè)用xslt樣式將xml解析為xhtml的類TransformBinder(兼容FF和IE7.0)
這幾天一直在研究xslt轉(zhuǎn)換xml為xhtml,前面文章有介紹 使用xslt將xml解析成xhtml 的文章2009-11-11用Asp與XML實(shí)現(xiàn)交互的一個(gè)實(shí)例源碼
用Asp與XML實(shí)現(xiàn)交互的一個(gè)實(shí)例源碼...2007-11-11氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-簡(jiǎn)介
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-簡(jiǎn)介...2007-02-02