• asp.net Xml操作类


    using System;
    using System.Xml;

    namespace WebLayout.App_Code
    {
    public class XmlHelper
    {
    public string XmlPath { get; set; }

    private XmlDocument xmldoc = new XmlDocument();
    /// <summary>
    /// 加载文件
    /// </summary>
    public void LoadXml()
    {
    try
    {
    xmldoc.Load(XmlPath);
    }
    catch (Exception e)
    {
    //文件加载失败
    }
    }

    /// <summary>
    /// 获取指定的节点
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <returns></returns>
    public XmlNode Node(string nodeName)
    {
    return xmldoc.SelectSingleNode(nodeName);
    }
    /// <summary>
    /// 获取指定节点下的所有直接子节点
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <returns></returns>
    public XmlNodeList NodeList(string nodeName)
    {
    XmlNode root = Node(nodeName);
    return root.ChildNodes;
    }
    /// <summary>
    /// 判断指定节点下是否有子节点
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <returns></returns>
    public bool IsHasChildNode(string nodeName)
    {
    return Node(nodeName).HasChildNodes;
    }

    /// <summary>
    /// 获取指定节点的文本
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <returns></returns>
    public string GetNodeText(string nodeName)
    {
    XmlNode curruentNode = Node(nodeName);
    return curruentNode.InnerText;
    }

    /// <summary>
    /// 获取节点指定的属性值
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <param name="attributeName">属性名字</param>
    /// <returns></returns>
    public string GetNodeAttributeValue(string nodeName, string attributeName)
    {
    XmlNode node = Node(nodeName);
    return node.Attributes[attributeName].Value;
    }

    /// <summary>
    /// 获取子节点的数量
    /// </summary>
    /// <param name="nodeName">节点</param>
    /// <returns></returns>
    public int GetChildNodeCount(string nodeName)
    {
    XmlNode node = Node(nodeName);
    return node.ChildNodes.Count;
    }

    }
    }

  • 相关阅读:
    tkinter center window
    get content of all input tag
    pyqt get dynamic content from js
    【python爬虫】selenium的三种等待
    【python爬虫】selenium常用方法总结
    【pathon基础】初识python
    【python爬虫】动态html
    【python爬虫】Xpath
    【python爬虫】正则表达式
    【python爬虫】cookie & session
  • 原文地址:https://www.cnblogs.com/something/p/3090930.html
Copyright © 2020-2023  润新知