This documentation is archived and is not being maintained.

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);

  }
}
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    // Create and load the XML document.
    XmlDocument* doc = new XmlDocument();
    String* xmlString = S"<book><title>Oberon's Legacy</title></book>";
    doc->Load(new StringReader(xmlString));

    // Create an XML declaration. 
    XmlDeclaration* xmldecl;
    xmldecl = doc->CreateXmlDeclaration(S"1.0",0,0);
    xmldecl->Encoding=S"UTF-8";
    xmldecl->Standalone=S"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);
}

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: