读写xml文件的2个小函数

2023-12-07 0 330

要利用DOM来存取XML文件,你必须将XML文件连结到HTML网页上。 #region读写xml文件的2个小函数,200542byhyc publicvoidSetXmlFileValue(stringxmlPath,stringAppKey,stringAppValue)//写xmlPath是文件路径+文件名,AppKey是KeyName,AppValue是Value { XmlDocumentxDoc=newXmlDocument(); xDoc.Load(xmlPath); XmlNodexNode; XmlElementxElem1; XmlElementxElem2; xNode=xDoc.SelectSingleNode(\”//appSettings\”); xElem1=(XmlElement)xNode.SelectSingleNode(\”//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); } publicvoidGetXmlFileValue(stringxmlPath,stringAppKey,refstringAppValue)//读xmlPath是文件路径+文件名,AppKey是KeyName,AppValue是Value { XmlDocumentxDoc=newXmlDocument(); xDoc.Load(xmlPath); XmlNodexNode; XmlElementxElem1; xNode=xDoc.SelectSingleNode(\”//appSettings\”); xElem1=(XmlElement)xNode.SelectSingleNode(\”//add[@key=\’\”+AppKey+\”\’]\”); if(xElem1!=null) { AppValue=xElem1.GetAttribute(\”value\”); } else { //MessageBox.Show(\”Thereisnotanyinformation!\”); } } #endregion

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 XML/RSS 读写xml文件的2个小函数 https://www.u-9.cn/biancheng/xmlrss/126089.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务