使用xmltextreader對(duì)象讀取xml文檔示例
更新時(shí)間:2014年02月25日 10:22:44 作者:
這篇文章主要介紹了使用xmltextreader對(duì)象讀取xml文檔的示例,需要的朋友可以參考下
XML源文件為note.xml
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml; //引入命名空間
namespace ReadXmlDemo
{
class Program
{
static void Main(string[] args)
{
//打開xml
XmlTextReader textReader = new XmlTextReader("C:\\note.xml");
//讀取數(shù)據(jù)
while (textReader.Read())
{
textReader.MoveToElement();
Console.WriteLine("XmlTextReader Properties Test");
Console.WriteLine("==============================");
Console.WriteLine("Name:"+textReader.Name);
Console.WriteLine("Base URI:"+textReader.BaseURI);
Console.WriteLine("Local Name:"+textReader.LocalName);
Console.WriteLine("Attribute Count:"+textReader.AttributeCount.ToString());
Console.WriteLine("Line Number:"+textReader.LineNumber.ToString());
Console.WriteLine("Node Type:"+textReader.NodeType.ToString());
Console.WriteLine("Attribute Count:"+textReader.Value.ToString());
}
Console.ReadKey();
}
}
}
運(yùn)行結(jié)果如下:
相關(guān)文章
C#實(shí)現(xiàn)百分比轉(zhuǎn)小數(shù)的方法
這篇文章主要介紹了C#實(shí)現(xiàn)百分比轉(zhuǎn)小數(shù)的方法,涉及C#進(jìn)行數(shù)值計(jì)算的相關(guān)技巧,需要的朋友可以參考下2015-06-06C#?winform跨線程操作控件的實(shí)現(xiàn)
本文主要介紹了C#?winform跨線程操作控件的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06C# WinForm實(shí)現(xiàn)窗體上控件自由拖動(dòng)功能示例
這篇文章主要介紹了C# WinForm實(shí)現(xiàn)窗體上控件自由拖動(dòng)功能,涉及WinForm控件屬性及事件響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2017-07-07Unity3D游戲開發(fā)數(shù)據(jù)持久化PlayerPrefs的用法詳解
在本篇文章里小編給大家整理了關(guān)于Unity3D游戲開發(fā)之?dāng)?shù)據(jù)持久化PlayerPrefs的使用的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們參考下。2019-08-08