国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

讀寫xml文件的2個小函數(shù)

瀏覽:58日期:2022-06-04 09:30:06
要利用DOM 來存取XML 文件,你必須將XML 文件連結(jié)到HTML 網(wǎng)頁上。

#region 讀寫xml文件的2個小函數(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)文章:
主站蜘蛛池模板: 富蕴县| 三台县| 金平| 保山市| 石屏县| 建宁县| 江西省| 青岛市| 内江市| 当阳市| 鲁甸县| 灵台县| 资兴市| 江孜县| 泾川县| 宜黄县| 白银市| 景宁| 大新县| 江源县| 贵德县| 嵊州市| 康定县| 怀仁县| 合江县| 乌鲁木齐县| 化隆| 湖州市| 富川| 唐山市| 巍山| 大姚县| 潞西市| 安宁市| 惠水县| 津市市| 舒兰市| 汕尾市| 临沭县| 徐水县| 灵宝市|