Read XML document by node type : Xml Node « XML « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / CSharp Tutorial » XML » Xml Node 
26. 11. 12. Read XML document by node type
using System;
using System.Xml;

class MainClass
{
    static void Main(string[] args)
    {
        int DecCounter=0, PICounter=0, DocCounter=0, CommentCounter=0, ElementCounter=0, AttributeCounter=0, TextCounter=0, WhitespaceCounter=0;
        XmlTextReader reader = new XmlTextReader(@"C:\books.xml");

        while (reader.Read())
        {
            XmlNodeType type = reader.NodeType; 
            switch (type) {
                case XmlNodeType.XmlDeclaration:
                    DecCounter++;
                    break;
                case XmlNodeType.ProcessingInstruction:
                    PICounter++;
                    break;
                case XmlNodeType.DocumentType:
                    DocCounter++;
                    break;
                case XmlNodeType.Comment:
                    CommentCounter++;
                    break;
                case XmlNodeType.Element:
                    ElementCounter++;
                    if (reader.HasAttributes)
                        AttributeCounter += reader.AttributeCount;
                    break;
                case XmlNodeType.Text:
                    TextCounter++;
                    break;
                case XmlNodeType.Whitespace:
                    WhitespaceCounter++;
                    break;
            }               
        }
        Console.WriteLine("White Spaces:" +WhitespaceCounter.ToString());
        Console.WriteLine("Process Instructions:" +PICounter.ToString());
        Console.WriteLine("Declaration:" +DecCounter.ToString());
        Console.WriteLine("White Spaces:" +DocCounter.ToString());
        Console.WriteLine("Comments:" +CommentCounter.ToString());
        Console.WriteLine("Attributes:" +AttributeCounter.ToString());
    }
}
26. 11. Xml Node
26. 11. 1. Find nodes by name
26. 11. 2. Select Nodes By Namespace
26. 11. 3. XmlNode: InsertAfter FirstChild
26. 11. 4. Xml Node List
26. 11. 5. Select nodes from XmlDocument
26. 11. 6. Recursively display XmlNode
26. 11. 7. Replace Children
26. 11. 8. Root Node
26. 11. 9. Insert after
26. 11. 10. Append element
26. 11. 11. Get current value and depth during the XML document reading process
26. 11. 12. Read XML document by node type
w___ww___._j__a__va__2_s._c___o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.