要利用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