Get xml node type : XmlNodeType « XML « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » XML » XmlNodeType 
Get xml node type
 

#include "stdafx.h"

#using <system.xml.dll>

using namespace System;
using namespace System::Xml;

void main()
{
    XmlReader ^reader;
    reader = XmlReader::Create("..\\Monsters.xml");
   while (reader->Read()){
            switch (reader->NodeType)
            {
                case XmlNodeType::Comment:
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Value);
                    break;
                case XmlNodeType::Element:
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Name);
                    if (reader->HasAttributes)
                    {
                        while (reader->MoveToNextAttribute())
                        {
                            Console::WriteLine(reader->Depth);
                            Console::WriteLine(reader->Name);
                            Console::WriteLine(reader->Value);
                        }
                        reader->MoveToElement();
                    }
                    if (reader->IsEmptyElement)
                    {
                        Console::WriteLine(reader->Depth);
                        Console::WriteLine(reader->Name);
                    }
                    break;
                case XmlNodeType::EndElement:
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Name);
                    break;
                case XmlNodeType::Text:
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Value);
                    break;
                case XmlNodeType::XmlDeclaration:
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Name);

                    if (reader->HasAttributes)
                    {
                        while (reader->MoveToNextAttribute())
                        {
                            Console::WriteLine(reader->Depth);
                            Console::WriteLine(reader->Name);
                            Console::WriteLine(reader->Value);
                        }
                    }
                    reader->MoveToElement();
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Name);
                    break;
                case XmlNodeType::Whitespace:
                    break;
                default:
                    Console::WriteLine("***UKNOWN*** node");
                    Console::WriteLine(reader->Depth);
                    Console::WriteLine(reader->Name);
                    Console::WriteLine(reader->Value);
            }
        }
}

   
  
Related examples in the same category
1.Is empty element
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.