This documentation is archived and is not being maintained.

XmlSignificantWhitespace.NodeType Property

Gets the type of the current node.

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

public override XmlNodeType NodeType { get; }

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;
using System.IO;
using System.Xml;

public class Sample {

  private XmlNode currNode;
  private const String filename="space.xml";
  XmlTextReader reader=null;

  public static void Main() {

    Sample test = new Sample();
  }
  public Sample() {

      XmlDocument doc = new 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. 
  public void ReadFile(String filename) {
    try {

      reader = new XmlTextReader(filename);
      String sNodeType = null;
      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 != null)
         reader.Close();
    }
   }

   public static String NodeTypeToString(XmlNodeType nodetype) {
      String sNodeType = null;
      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;
   }
}
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

public __gc class Sample {

private:
   XmlNode* currNode;
   XmlTextReader* reader;

public:
   Sample() {
      reader=0;
      String* filename=S"space.xml";   
      XmlDocument* doc = new XmlDocument();
      doc->LoadXml(S"<!-- Sample XML fragment -->" 
                   S"<author xml:space='preserve'>" 
                   S"<first-name>Eva</first-name>"
                   S"<last-name>Corets</last-name>"  
                   S"</author>"); 

      Console::WriteLine(S"InnerText before...");
      Console::WriteLine(doc->DocumentElement->InnerText);

      // Add white space.     
      currNode=doc->DocumentElement;
      XmlSignificantWhitespace* sigws=doc->CreateSignificantWhitespace(S"\t");
      currNode->InsertAfter(sigws, currNode->FirstChild);

      Console::WriteLine();
      Console::WriteLine(S"InnerText after...");
      Console::WriteLine(doc->DocumentElement->InnerText);

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

   }

   // Parse the file and print out each node.
   void ReadFile(String* filename) {
      try {

         reader = new XmlTextReader(filename);
         String* sNodeType = 0;
         while (reader->Read()) {       
            sNodeType = NodeTypeToString(reader->NodeType); 
            // Print the node type, name, and value.
            Console::WriteLine(S"{0}<{1}> {2}", sNodeType, reader->Name, reader->Value);
         }
      }
      __finally {
         if (reader != 0)
            reader->Close();
      }
   }

   static String* NodeTypeToString(XmlNodeType nodetype) {
      String* sNodeType = 0;
      switch (nodetype) {
         case XmlNodeType::None:
            sNodeType = S"None";
            break;
         case XmlNodeType::Element:
            sNodeType = S"Element";
            break;
         case XmlNodeType::Attribute:
            sNodeType = S"Attribute";
            break;
         case XmlNodeType::Text:
            sNodeType = S"Text";
            break;
         case XmlNodeType::Comment:
            sNodeType = S"Comment";
            break;
         case XmlNodeType::Document:
            sNodeType = S"Document";
            break;
         case XmlNodeType::Whitespace:
            sNodeType = S"Whitespace";
            break;
         case XmlNodeType::SignificantWhitespace:
            sNodeType = S"SignificantWhitespace";
            break;
         case XmlNodeType::EndElement:
            sNodeType = S"EndElement";
            break;
      }
      return sNodeType;
   }
};

int main() {
   new Sample();
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: