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

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

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

瀏覽:281日期: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
標(biāo)簽: XML/RSS
相關(guān)文章:
主站蜘蛛池模板: 马边| 伊宁县| 黄骅市| 彰武县| 浮梁县| 简阳市| 布尔津县| 沾化县| 高平市| 柳州市| 阿鲁科尔沁旗| 康乐县| 龙井市| 太仆寺旗| 泉州市| 井冈山市| 察隅县| 荣昌县| 会泽县| 桐乡市| 工布江达县| 衡南县| 河西区| 涡阳县| 永福县| 公安县| 眉山市| 马关县| 丹寨县| 禄丰县| 晋宁县| 铜鼓县| 临漳县| 塔城市| 桂东县| 荣成市| 壶关县| 荔浦县| 咸丰县| 西盟| 闸北区|