Solved

What causes the value of  "reader.NodeType" to have 1 of the following 3 values when reading a record an XML file: EndElement, Whitespace, Text?

Posted on 2010-09-09
1
358 Views
Last Modified: 2013-12-17
I am writing my first C# Console application and I'm trying to understand what causes the value of  "reader.NodeType" to have 1 of the following 3 values when reading a record from the following XML file:
1) EndElement
2) Whitespace
3) Text

Snippet of code
------------------
XmlTextReader reader = new XmlTextReader("C:\\rbc.xml");      
            StreamWriter sw = new StreamWriter("C:\\output.txt");
            while (reader.Read())            
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "csc:check_number")

Sample XML file:
--------------------------
<?xml version="1.0"?>
<csc:Cion_Index_File
    xmlns:csc="http://rt.csc.com/xml/Cion_Index_File">
<csc:header>
    <csc:version>1.0</csc:version>
    <csc:customer_name>              </csc:customer_name>
    <csc:request_id>DD </csc:request_id>
    <csc:creation_date>20100909</csc:creation_date>
    <csc:creation_time>082723</csc:creation_time>
    <csc:creation_host>bbd-ce</csc:creation_host>
    <csc:content_type>CHECK</csc:content_type>
    <csc:item_count>602</csc:item_count>
    <csc:image_file_name>0.img</csc:image_file_name>
    <csc:input_request_file></csc:input_request_file>
</csc:header>
<csc:item>
    <csc:processing_date>20100907</csc:processing_date>
    <csc:item_sequence_number>000002500480784</csc:item_sequence_number>
    <csc:account_number>00000000000004444444</csc:account_number>
    <csc:check_number>000000903485725</csc:check_number>
    <csc:amount>0000305200</csc:amount>
    <csc:routing_transit>896888848</csc:routing_transit>
    <csc:bank_number>7777</csc:bank_number>
    <csc:transaction_code></csc:transaction_code>
    <csc:data1></csc:data1>
    <csc:data2></csc:data2>
    <csc:data3></csc:data3>
    <csc:userField></csc:userField>
    <csc:image_offset>17737464</csc:image_offset>
    <csc:image_length>019792</csc:image_length>
    <csc:image_side>A</csc:image_side>
</csc:item>
</csc:Cion_Index_File>

0
Comment
Question by:zimmer9
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 33643108
1) EndElement

XmlNodeType Enumeration
http://msdn.microsoft.com/en-us/library/system.xml.xmlnodetype(v=VS.71).aspx

   An end element tag.
   Example XML: </item>

2) Whitespace

Handling White Space with XmlTextReader
http://msdn.microsoft.com/en-us/library/aa720125(v=VS.71).aspx

• Space (ASCII space, 0x20)
• Carriage return (CR, 0x0D)
• Line feed (LF, 0x0A)
• Horizontal tab (0X09

3) Text

The text content of a node.
A Text node cannot have any child nodes. It can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now