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 */
public String get_Standalone ()

/** @property */
public void set_Standalone (String value)

public function get Standalone () : String

public function set Standalone (value : String)

Not applicable.

Property Value

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

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        // 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.set_Encoding("UTF-8");
        xmlDecl.set_Standalone("yes");

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

        // Display the modified XML document 
        Console.WriteLine(doc.get_OuterXml());
    } //main
} //Sample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: