zoukankan      html  css  js  c++  java
  • C#操作XML

    
    #region 操作XML
    private static XmlDocument xmldoc = new XmlDocument();
    private static JM_A ja = new JM_A();
    /// <summary>
    /// 查询XML
    /// </summary>
    /// <param name="key">查找标记</param>
    /// <returns>XML值</returns>
    public static String xml_select(String key)
    {
    try
    {
    xmldoc.Load(
    "config.xml");
    XmlNode root
    = xmldoc.SelectSingleNode("info");
    XmlNodeList Li
    = root.ChildNodes;
    String value
    = "";
    foreach (XmlNode item in Li)
    {
    XmlElement eL
    = (XmlElement)item;
    if (key == eL.Name)
    {
    value
    = eL.InnerText;
    break;
    }
    }
    return ja.AESDecrypt(value);
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    return "";
    throw new Exception("XML操作出错");
    }
    }
    /// <summary>
    /// 修改XML
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public static void xml_update(String key, String value)
    {
    try
    {
    xmldoc.Load(
    "config.xml");
    XmlNode root
    = xmldoc.SelectSingleNode("info");
    XmlNodeList Li
    = root.ChildNodes;
    foreach (XmlNode item in Li)
    {
    XmlElement eL
    = (XmlElement)item;
    if (key == eL.Name)
    {
    Console.WriteLine(
    "111111");
    eL.InnerText
    = ja.AESEncrypt(value);
    xmldoc.Save(
    "config.xml");
    break;
    }
    }
    }
    catch
    {
    throw new Exception("XML操作出错");
    }
    }
    #endregion
    }
  • 相关阅读:
    构建之法阅读笔记06
    构建之法阅读笔记05
    第九周进度条
    团队开发之个人博客九
    团队开发之个人博客八(4月27)
    无人机第二波
    团队开发之个人博客七
    无人机学习第一波
    团队开发之个人博客六
    第八周进度条
  • 原文地址:https://www.cnblogs.com/beeone/p/1998293.html
Copyright © 2011-2022 走看看