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

     using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml;

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                 GetDataSet();
              
            }
        }


        private void GetDataSet()
        {
         
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("./xml/xmlfile2.xml"));//你的xml文件
            XmlNodeList xmlList = xmlDoc.SelectNodes("/Users/CUsers");
            foreach(XmlNode xnl in xmlList){
                XmlNodeList xode = xnl.ChildNodes ;
              
                foreach (XmlNode xnod in xode)
                {
                   
                    //XmlNodeList xe = (XmlNodeList)xmlNo;
                    XmlElement xe = (XmlElement)xnod;
                    {
                        if (xe.Name == "UserID")
                        {
                            Response.Write("UserID  :"+xe.InnerText);
                        }

                        if (xe.Name == "UserName")
                        {
                            Response.Write("UserName :"+xe.InnerText);
                        }

                        if (xe.Name == "RealName")
                        {
                            Response.Write("RealName :" + xe.InnerText);
                        }

                        if (xe.Name == "CreateDate")
                        {
                            Response.Write("CreateDate:" + xe.InnerText + "<br/>");
                        }
                   }

                   
                }
            }
    }
    }

    --------------------------------------------------------------------------------

    <?xml version="1.0" encoding="utf-8" ?>
    <Users>
      <CUsers>
        <UserID>Admin</UserID>
        <UserName>Admin</UserName>
        <RealName>Admin</RealName>
        <CreateDate>1980-10-01T00:00:00</CreateDate>
      </CUsers>
      <CUsers>
        <UserID>Admin1</UserID>
        <UserName>Admin1</UserName>
        <RealName>Admin1</RealName>
        <CreateDate>1980-10-01T00:00:00</CreateDate>
      </CUsers>
      <CUsers>
        <UserID>Admin2</UserID>
        <UserName>Admin2</UserName>
        <RealName>Admin2</RealName>
        <CreateDate>1980-10-01T00:00:00</CreateDate>
       </CUsers>
    </Users>

  • 相关阅读:
    android应用框架搭建------BaseActivity
    Android中Application类用法
    Android App框架设计之编写基类BaseActivity
    android Application类的详细介绍
    Linux使用jstat命令查看jvm的GC情况
    cocos2dx怎样设置ios和Android横屏竖屏的几种方法
    网络请求 http get post 一
    Java多线程中wait, notify and notifyAll的使用
    一个人生活,怎样摆脱孤独提升幸福感?
    js控制文本框仅仅能输入中文、英文、数字与指定特殊符号
  • 原文地址:https://www.cnblogs.com/dingdingmao/p/3146609.html
Copyright © 2011-2022 走看看