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
361 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

19 Experts available now in Live!

Get 1:1 Help Now