Both sections print out the same thing, chapter1 and chapter2.
Why does the first section of the code have to use reader.Value and the second section has to use reader.ReadInnerXML? If I swap the two or use one of the two in both instances, it does not work. So they are not interchangeable
C#.NET ProgrammingASP.NET
Last Comment
Arnold Layne
8/22/2022 - Mon
Imran Javed Zia
Hi,
as read method reads all nodes, while ReadToFollowing searches the specified one.
Hi Imran, thanks for your answer. Your links seem to explain how the XMLReader class works and how the Read method works, but I didn't see any explanation in your links as to when and why someone would use value to get the value and when and why someone should use ReadInnerXML instead. I understand what the Read Method and the Readtofollowing method are doing but I don't understand why the value in the element is accessed two different ways, depending upon which reading method is used.
Arnold Layne
ASKER
Hi Carl, your answer seems to be close and you seem to understand my question. Chapter is a text element, so after calling readtofollowing("chapter"), it is already on a text element. So why would I need to call read again to get to a text element before I can call read.value? And what is the key difference between the Read.Value and ReadInnerXML method? They both seem to do the same thing, assuming the element that has been read to, is a text element.
First answer was correct, but second answer told me the key difference to understand and I saw this exact behavior when I ran it in the debugger, which I should have done initially. So the Read method will take you to the text node portion of an element node, while readtofollowing takes you to the element node itself, but not it's inner text node, and therefore needs to call ReadInnerXML to get the value from the text node portion of the element rather than merely calling .Value as it would be able to if the cursor were actually on the text node portion.
as read method reads all nodes, while ReadToFollowing searches the specified one.
Please go through following for more details:
http://msdn.microsoft.com/en-us/library/ms162536(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.read(v=vs.110).aspx
http://forums.asp.net/t/1518948.aspx
http://msdn.microsoft.com/en-us/library/9d83k261(v=vs.110).aspx
Thanks