关于XmlTextReader.Read()

    今天终于搞清楚 XmlTextReader 的 Read 方法读 node 的机制了。他会把读到的回车阿,空格阿什么的都当成是一个Node。以前一直没能很好的理解这一点,所以总觉得有点怪怪的。现在好了,可以安心的睡一觉了。
一下是两端代码的实例:
测试的代码很简单
None.gif XmlTextReader BooksReader  =   new  XmlTextReader( @" E:\MCAD+MCSD\MCAD\2663\Practices\Mod02\books.xml " );
None.gif
None.gif
while  (BooksReader.Read()) 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  listBox1.Items.Add(BooksReader.Name);
InBlock.gif

//Xml File Version 1
None.gif <? xml version='1.0' ?>
None.gif
<!--  This file represents a fragment of a book store inventory database  -->
None.gif
< bookstore >
None.gif
< book  genre ="autobiography"  publicationdate ="1981"  ISBN ="1-861003-11-0" >
None.gif    
< title > The Autobiography of Benjamin Franklin </ title >
None.gif    
< author >
None.gif      
< first-name > Benjamin </ first-name >
None.gif      
< last-name > Franklin </ last-name >
None.gif    
</ author >
None.gif    
< price > 8.99 </ price >
None.gif  
</ book >
None.gif  
< book  genre ="novel"  publicationdate ="1967"  ISBN ="0-201-63361-2" >
None.gif    
< title > The Confidence Man </ title >
None.gif    
< author >
None.gif      
< first-name > Herman </ first-name >
None.gif      
< last-name > Melville </ last-name >
None.gif    
</ author >
None.gif    
< price > 11.99 </ price >
None.gif  
</ book >
None.gif  
< book  genre ="philosophy"  publicationdate ="1991"  ISBN ="1-861001-57-6" >
None.gif    
< title > The Gorgias </ title >
None.gif    
< author >
None.gif      
< name > Plato </ name >
None.gif    
</ author >
None.gif    
< price > 9.99 </ price >
None.gif  
</ book >
None.gif
</ bookstore >
//运行结果
r1.JPG

//XML File version 2
None.gif <? xml version='1.0' ?> <!--  This file represents a fragment of a book store inventory database  -->
None.gif
< bookstore >< book  genre ="autobiography"  publicationdate ="1981"  ISBN ="1-861003-11-0" >
None.gif    
< title > The Autobiography of Benjamin Franklin </ title >
None.gif    
< author >
None.gif      
< first-name > Benjamin </ first-name >
None.gif      
< last-name > Franklin </ last-name >
None.gif    
</ author >
None.gif    
< price > 8.99 </ price >
None.gif  
</ book >
None.gif  
< book  genre ="novel"  publicationdate ="1967"  ISBN ="0-201-63361-2" >
None.gif    
< title > The Confidence Man </ title >
None.gif    
< author >
None.gif      
< first-name > Herman </ first-name >
None.gif      
< last-name > Melville </ last-name >
None.gif    
</ author >
None.gif    
< price > 11.99 </ price >
None.gif  
</ book >
None.gif  
< book  genre ="philosophy"  publicationdate ="1991"  ISBN ="1-861001-57-6" >
None.gif    
< title > The Gorgias </ title >
None.gif    
< author >
None.gif      
< name > Plato </ name >
None.gif    
</ author >
None.gif    
< price > 9.99 </ price >
None.gif  
</ book >
None.gif
</ bookstore >
None.gif
None.gif
//运行结果
r2.JPG
posted on 2005-08-13 22:25 海盗 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Grisson/archive/2005/08/13/214313.html

XmlException: invalid data. System.Xml.XmlStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) Mono.Xml2.XmlTextReader.PeekChar () Mono.Xml2.XmlTextReader.ReadContent () Mono.Xml2.XmlTextReader.Read () System.Xml.XmlTextReader.Read () UnityEditor.AndroidXmlDocument..ctor (System.String path) UnityEditor.AndroidManifest..ctor (System.String path) UnityEditor.Android.PostProcessAndroidPlayer.CopyMainManifest (System.String target, System.String playerPackage) UnityEditor.Android.PostProcessAndroidPlayer.PostProcessInternal (System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args) UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316) UnityEditor.HostView:OnGUI()
最新发布
07-11
XmlException: Attribute name and qualified name must be identical. file:///D:/Lua_Dating538/Assets/Plugins/Android/AndroidManifest.xml Line 3, position 61. Mono.Xml2.XmlTextReader.ReadStartTag () Mono.Xml2.XmlTextReader.ReadContent () Mono.Xml2.XmlTextReader.ReadContent () Mono.Xml2.XmlTextReader.Read () System.Xml.XmlTextReader.Read () System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) UnityEditor.AndroidXmlDocument..ctor (System.String path) UnityEditor.AndroidManifest..ctor (System.String path) UnityEditor.Android.PostProcessAndroidPlayer.CopyMainManifest (System.String target, System.String playerPackage) UnityEditor.Android.PostProcessAndroidPlayer.PostProcessInternal (System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args) UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316) UnityEditor.HostView:OnGUI()
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值