zoukankan      html  css  js  c++  java
  • C#读取XML节点内容方法

       using    System;   
       using    System.Xml;   
       using    System.Xml.XPath;   
       using    System.Data;   
        
       class    ReadXML   
       {   
           public    static    void    Main()   
           {   
       string    sFile    =    "ReadXml.xml";   
        
       //method    1   
       XmlDocument    doc    =    new    XmlDocument();   
       doc.Load(sFile);   
       XmlNode    node    =    doc.DocumentElement["News"]["Content"];   
       Console.WriteLine(node.InnerText);   
        
       //method2   
       node    =    doc.SelectSingleNode("//Content");   
       Console.WriteLine(node.InnerText);   
        
       //similarly   
       node    =    doc.DocumentElement.SelectSingleNode("News/Content");   
       Console.WriteLine(node.InnerText);   
        
       //method    3   
       DataSet    ds    =    new    DataSet();   
       ds.ReadXml(sFile);   
       Console.WriteLine(ds.Tables[0].Rows[0]["Content"].ToString());   
        
       //method    4   
       XmlTextReader    reader    =    new    XmlTextReader(sFile);   
       while    (reader.Read())   
       {   
       if    (reader.Name    ==    "Content")   
       {   
       Console.WriteLine("***"    +    reader.ReadString());   
       break;   
       }   
       }   
        
       reader.Close();   
        
       //method    5   
        
       XPathDocument    xpdoc    =    new    XPathDocument(sFile);   
       XPathNavigator    xpnv    =    xpdoc.CreateNavigator();   
       xpnv.MoveToFirstChild();   
       xpnv.MoveToFirstChild();   
       xpnv.MoveToFirstChild();   
       xpnv.MoveToNext();xpnv.MoveToNext();xpnv.MoveToNext();   
       Console.WriteLine("pathnavigator:"    +    xpnv.Value);   
           }   
       }
  • 相关阅读:
    Jenkins以root用户运行的方法
    nginx进行反向代理,80端口使用
    centos7 开机启动服务链接说明
    开始写博客
    python 读取文件夹,目录中出现中文的问题
    python unrar 解压缩
    python远程下载
    kryo 序列化
    python 多线程实验
    python decorator模式
  • 原文地址:https://www.cnblogs.com/scgw/p/1498309.html
Copyright © 2011-2022 走看看