zoukankan      html  css  js  c++  java
  • 关于读取XML文件代码【学习笔记】

    public class XmlManager
    {
    private XmlDocument m_XMLDoc = null;
    public XmlManager(XmlDocument xmldoc)
    {
    m_XMLDoc = xmldoc;
    }
    public XmlManager(string path)
    {
    m_XMLDoc = new XmlDocument();
    m_XMLDoc.Load(path);
    }
    //读取指定节点下的指定子节点的text
    public string GetNodeText(string rootNodeName, string nodeName, string chileNodeName)
    {
    string value = "";
    try
    {
    XmlNodeList nodes = m_XMLDoc.SelectSingleNode(rootNodeName).ChildNodes;
    foreach (XmlNode node in nodes)
    {
    if (node.LocalName != nodeName)
    continue;
    XmlNode item = node.SelectSingleNode(chileNodeName);
    if (item != null)
    {
    value = item.InnerText;
    }
    break;
    }
    }
    catch (System.Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    return value;
    }
    ////设置指定节点下的指定子节点的text
    public void SaveNodeText(string rootNodeName, string nodeName, string chileNodeName, string value, string savePath)
    {
    try
    {
    XmlNodeList nodes = m_XMLDoc.SelectSingleNode(rootNodeName).ChildNodes;
    foreach (XmlNode node in nodes)
    {
    if (node.LocalName != nodeName)
    continue;
    XmlNode item = node.SelectSingleNode(chileNodeName);
    if (item != null)
    {
    item.InnerText = value;
    m_XMLDoc.Save(savePath);
    }
    break;
    }
    }
    catch (System.Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    }

    }

    抱着一颗学习的心态,一颗敬畏之心
  • 相关阅读:
    软件设计原则
    UML 类图
    Lambda 四大内置核心函数式接口
    Lambda 表达式简介
    vuex源码解析及简单实现
    websocket
    module.export / require 和 export / import
    关于form表单提交时required属性失效的问题
    更改mysql引擎后无法建立外键(navicat)
    关于Android studio SDK的安装与配置
  • 原文地址:https://www.cnblogs.com/zhuhongyang/p/7417565.html
Copyright © 2011-2022 走看看