网址大全 | 文章大全 | 精选文摘 | 桌面壁纸 | 站长资源 | 在线手册 | 幽默笑话 | 天气预报 | FLASH    | 歇后语
便民查询 | 成语词典 | 五笔字典 | 新华字典 | 周公解梦 | 在线算命 | 生日密码 | 网络电台 | 网站留言 | 许愿墙
您的位置:首页 >> 文章大全 > 网络编程 > C#
站内搜索:
网络编程专栏
VB.NETASP
ASP.NETC#
数据库PHP
技巧篇Delphi
相关文章
没有相关文章
百度搜索 全网 本站
本类排行 more>>
·C#的IO使用
·c#中如何获取时间!
·C#实现的18位身份证格...
·用C#读取XML的元素和...
·winfrom中的datagrid...
·如何用C#语言构造蜘蛛...
·C#的消息处理方法
·C#部分函数列表
·C#资料下载收藏
·实现C#和VB.net之间的...
最新文章 more>>
·《网站配色方案》系列...
·《网站配色方案》系列...
·岳飞传的流程攻略
·百度漂亮 但Google更...
·个人站长的胜利 新网...
·搜搜问问抢不了百度知...
·视频网站接连败退 营...
·曹操传 杨家将传奇 官...
·专家为股民支招:网络...
·优秀站长访谈:个人网...
用C#读取XML的元素和属性

[ 作者:佚名 来源:网络 点击数:110 加入时间:2006-11-7 ]

【双击左键自动滚屏】【图片上滚动鼠标滚轮变焦图片】 【字体:放大 正常 缩小】 字体颜色:
便民查询  中华五千年  世界五千年  万年历  天气预报  周公解梦  脑筋急转弯  在线翻译  电信话费查询
 <?xml version="1.0" encoding="gb2312" ?>
<musiclession>
    <student ID="s101">
        <name>李华</name>
        <age>12</age>
        <score>92</score>
    </student>
    <student ID="s102">
        <name>笑林</name>
        <age>22</age>
        <score>82</score>
    </student>
    <student ID="s103">
        <name>王明</name>
        <age>18</age>
        <score>90</score>
    </student>
</musiclession>
using System;
using System.Xml;

namespace DOMTest
{
    class DOM
    {
        private static void PrintElement(XmlDocument document)
        {
            //获取所有的Node
            XmlNodeList nodeList=document.GetElementsByTagName("*");
            //打印每一个node的名称
            for(int i=0;i<nodeList.Count;i++)
            {
                XmlNode node=nodeList.Item(i);
                Console.WriteLine(node.Name);
            }
        }

        private static void PrintAttributes(XmlDocument document)
        {
            XmlNodeList nodeList=document.GetElementsByTagName("*");
            XmlNamedNodeMap nameNodeMap;
            XmlElement element;
            XmlAttribute attribute;
            string attributeName;
            string attributeValue;

            for(int i=0;i<nodeList.Count;i++)
            {
                element=(XmlElement)nodeList.Item(i);
                Console.WriteLine(element.Name+":"+element.ChildNodes[0].Value);
                nameNodeMap=element.Attributes;
                if(nameNodeMap!=null)
                {
                    for(int j=0;j<nameNodeMap.Count;j++)
                    {
                        attribute=(XmlAttribute)nameNodeMap.Item(j);
                        attributeName=attribute.Name;
                        attributeValue=attribute.Value;
                        Console.WriteLine("属性是:"+attributeName+"="+attributeValue);
                    }
                }
            }
        }
        [STAThread]
        static void Main(string[] args)
        {
            XmlDocument document =new XmlDocument();
            document.Load("student.xml");
            Console.WriteLine("元素是:");
            PrintElement(document);

//            Console.WriteLine("元素属性是:");
//            PrintAttributes(document);
        }
    }
}

国家纸币  自考信息  度量转换  搜索引擎指南  城市经纬度  脑筋急转弯  各国资料  名言辞典  违章查询
·上一篇文章:Windows 消息大全使用详解
·下一篇文章:怎样删除流氓软件-ewido
百度搜索更多内容:用C#读取XML的元素和属性
推荐文档】 【打印文档】 【返回页首】 【关闭窗口