xml 파일 을 읽 고 쓰 는 작은 함수 2 개

DOM 을 이용 해 야 돼 요. XML 액세스 파일,XML 을 HTML 에 파일 연결 홈 페이지 에.region xml 파일 을 읽 고 쓰 는 작은 함수 2 개,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("//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); } 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("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']"); if ( xElem1 != null ) { AppValue=xElem1.GetAttribute ("value"); } else { // MessageBox.Show ("There is not any information!"); } } #endregion

좋은 웹페이지 즐겨찾기