MSDN Documentation

.NET Framework > System.Xml > XmlNodeReader > XmlSpace Property

XmlSpace Property

Namespace: System.Xml

Assembly: System.Xml.dll

Syntax


public System.Xml.XmlSpace XmlSpace { get; }
            

Property Value

A System.Xml.XmlSpace value indicating the current white space handling.

Remarks

The XmlSpace property tells you how to interpret white space within the XML document. It can be one of the following values:

This property reflects the xml:space attribute found in the XML document.

Example

The following example demonstrates how to retrieve the XmlSpace value using an XmlNodeReader.


using System;
using System.Xml;

public class Example
{
    public static void Main(string[] args)
    {
        string xmlString = @"
        <root xmlns:xml=""http://www.w3.org/XML/1998/namespace"" xml:space=""preserve"">
            <element>  Some text with   significant spaces. </element>
        </root>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlString);

        XmlNodeReader reader = new XmlNodeReader(doc);

        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == "root")
            {
                XmlSpace space = reader.XmlSpace;
                Console.WriteLine($""XmlSpace attribute: {space}"");
            }
        }
        reader.Close();
    }
}
            

Output


XmlSpace attribute: Preserve
            
Note: The xml:space attribute is inherited. If it's not explicitly set on an element, it inherits the value from its parent element.

Requirements

Interface Method Platform .NET Framework
System.Xml.IXmlLineInfo LineNumber, LinePosition .NET Framework, .NET Core, .NET Standard Supported in: .NET Framework 2.0, .NET Core 2.0, .NET Standard 2.0

See Also