XmlDeclaration.Standalone Property

 

Gets or sets the value of the standalone attribute.

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

public string Standalone { get; set; }

Property Value

Type: System.String

Valid values are yes if all entity declarations required by the XML document are contained within the document or no if an external document type definition (DTD) is required. If a standalone attribute is not present in the XML declaration, this property returns String.Empty.

The following example creates an XmlDeclaration node and adds it to an XML document.

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    // Create and load the XML document.
    XmlDocument doc = new XmlDocument();
    string xmlString = "<book><title>Oberon's Legacy</title></book>";
    doc.Load(new StringReader(xmlString));

    // Create an XML declaration. 
    XmlDeclaration xmldecl;
    xmldecl = doc.CreateXmlDeclaration("1.0",null,null);
    xmldecl.Encoding="UTF-8";
    xmldecl.Standalone="yes";     

    // Add the new node to the document.
    XmlElement root = doc.DocumentElement;
    doc.InsertBefore(xmldecl, root);

    // Display the modified XML document 
    Console.WriteLine(doc.OuterXml);

  }
}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: