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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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