Export (0) Print
Expand All

XmlSignificantWhitespace::NodeType Property

Gets the type of the current node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public:
virtual property XmlNodeType NodeType {
	XmlNodeType get () override;
}

Property Value

Type: System.Xml::XmlNodeType
For XmlSignificantWhitespace nodes, this value is XmlNodeType.SignificantWhitespace.

The following example adds significant white space to the document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
public ref class Sample
{
private:
   XmlNode^ currNode;
   XmlTextReader^ reader;

public:
   Sample()
   {
      reader = nullptr;
      String^ filename = "space.xml";
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<!-- Sample XML fragment -->" 
      "<author xml:space='preserve'>" 
      "<first-name>Eva</first-name>" 
      "<last-name>Corets</last-name>" 
      "</author>" );
      Console::WriteLine( "InnerText before..." );
      Console::WriteLine( doc->DocumentElement->InnerText );

      // Add white space.     
      currNode = doc->DocumentElement;
      XmlSignificantWhitespace^ sigws = doc->CreateSignificantWhitespace( "\t" );
      currNode->InsertAfter( sigws, currNode->FirstChild );
      Console::WriteLine();
      Console::WriteLine( "InnerText after..." );
      Console::WriteLine( doc->DocumentElement->InnerText );

      // Save and then display the file.
      doc->Save( filename );
      Console::WriteLine();
      Console::WriteLine( "Reading file..." );
      ReadFile( filename );
   }


   // Parse the file and print out each node. 
   void ReadFile( String^ filename )
   {
      try
      {
         reader = gcnew XmlTextReader( filename );
         String^ sNodeType = nullptr;
         while ( reader->Read() )
         {
            sNodeType = NodeTypeToString( reader->NodeType );

            // Print the node type, name, and value.
            Console::WriteLine( "{0}<{1}> {2}", sNodeType, reader->Name, reader->Value );
         }
      }
      finally
      {
         if ( reader != nullptr )
                  reader->Close();
      }

   }

   static String^ NodeTypeToString( XmlNodeType nodetype )
   {
      String^ sNodeType = nullptr;
      switch ( nodetype )
      {
         case XmlNodeType::None:
            sNodeType = "None";
            break;

         case XmlNodeType::Element:
            sNodeType = "Element";
            break;

         case XmlNodeType::Attribute:
            sNodeType = "Attribute";
            break;

         case XmlNodeType::Text:
            sNodeType = "Text";
            break;

         case XmlNodeType::Comment:
            sNodeType = "Comment";
            break;

         case XmlNodeType::Document:
            sNodeType = "Document";
            break;

         case XmlNodeType::Whitespace:
            sNodeType = "Whitespace";
            break;

         case XmlNodeType::SignificantWhitespace:
            sNodeType = "SignificantWhitespace";
            break;

         case XmlNodeType::EndElement:
            sNodeType = "EndElement";
            break;
      }
      return sNodeType;
   }

};

int main()
{
   gcnew Sample;
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft