zoukankan      html  css  js  c++  java
  • 读取XML文件

    读取XML文件:
    using System.Xml;

      protected void readXml()
      {
       try
       {
        System.Xml.XmlDocument mXmlDoc=new System.Xml.XmlDocument();
        mXmlDoc.Load(Server.MapPath("filepath"));
        string nettype=mXmlDoc.SelectNodes("//Root/Nettype")[0].InnerText;
        int cells=int.Parse(mXmlDoc.SelectNodes("//Root/Cells")[0].InnerText);
        XmlNodeList  mXmlNodes=mXmlDoc.SelectNodes("//Root/IPlink");
        foreach(XmlNode IPlinkchildlNode in mXmlNodes)
        {
         int icount=int.Parse(IPlinkchildlNode.ChildNodes[2].InnerText);          
        }
       }
       catch
       {
        /*
        可能的错误是:1、配置文件不存在
            2、配置文件内容被损坏
        */

       }

      }


    xxx.xml
    <?xml version="1.0"?>
    <Root>
       <Nettype>net</Nettype>
       <Totalnum>6</Totalnum>
       <Cells>2</Cells>
       <IPlink>
          <Name>站点1</Name>
          <IP>192.8.198.1</IP>
          <Sequence>1</Sequence>
       </IPlink>
       <IPlink>
          <Name>站点2</Name>
          <IP>192.8.198.2</IP>
          <Sequence>2</Sequence>
       </IPlink>
       … …
    </Root>

  • 相关阅读:
    CF891E Lust
    Comet OJ 2019 夏季欢乐赛题解
    CF1098E Fedya the Potter
    CF1063F String Journey
    P4218 [CTSC2010]珠宝商
    AGC028 E
    51Nod 1584 加权约数和
    51Nod 1769 Clarke and math2
    Educational Codeforces Round 67
    斯特林数学习笔记
  • 原文地址:https://www.cnblogs.com/xiaodi/p/131364.html
Copyright © 2011-2022 走看看