綠(lǜ)色資源網:您身邊最放心的安全下(xià)載站(zhàn)! 最新軟件|熱門排行|軟件分類|軟件專題|廠商大全

綠色資源網

技術教程
您的位置:首頁網絡編程Xml編程 → 讀寫xml文件的2個(gè)小函數(shù)

讀寫xml文件的2個小函數

我要評論 2010/02/07 12:56:10 來源:綠色資源網 編(biān)輯:佚名 [ ] 評論:0 點擊:348次

#region 讀寫xml文件的2個小(xiǎo)函數,2005 4 2 by hyc

  public void SetXmlFilevalsue(string xmlPath,string AppKey,string AppValue)//寫xmlPath是文件路徑+文件名(míng),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 GetXmlFilevalsue(string xmlPath,string AppKey,ref string AppValue)//讀xmlPath是文件路徑+文件名,AppKey是 Key Name,AppValue是(shì)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

關鍵詞:xml

閱讀本文後您有什麽感想? 已有 人給出評價!

  • 1 歡迎(yíng)喜歡
  • 1 白癡
  • 1 拜托
  • 1 哇(wa)
  • 1 加油(yóu)
  • 1 鄙視
免费人欧美成又黄又爽的视频丨一本色道久久88综合日韩精品丨国产专区日韩精品欧美色丨午夜无遮挡男女啪啪视频丨国产欧美日韩综合精品一区二区丨亚洲精品无码不卡在线播HE丨亚洲精品国产精品国自产观看丨日韩国产高清av不卡