Standalone Property
Collapse the table of content
Expand the table of content

XmlDeclaration.Standalone Property

Gets or sets the value of the standalone attribute.

[Visual Basic]
Public Property Standalone As String
public string Standalone {get; set;}
public: __property String* get_Standalone();
public: __property void set_Standalone(String*);
public function get Standalone() : String;
public function set Standalone(String);

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 DTD is required. If a standalone attribute is not present in the XML declaration, this property returns String.Empty.


[Visual Basic, C#, C++] The following example creates an XmlDeclaration node and adds it to an XML document.

[Visual Basic] 
Imports System
Imports System.IO
Imports System.Xml
public class Sample 

  public shared sub Main() 
    ' Create and load the XML document.
    Dim doc as XmlDocument = new XmlDocument()
    Dim xmlString as string = "<book><title>Oberon's Legacy</title></book>"
    doc.Load(new StringReader(xmlString))
    ' Create an XML declaration. 
    Dim xmldecl as XmlDeclaration 
    xmldecl = doc.CreateXmlDeclaration("1.0",nothing, nothing)
    ' Add the new node to the document.
    Dim root as XmlElement = doc.DocumentElement
    doc.InsertBefore(xmldecl, root)
    ' Display the modified XML document 
  end sub
end class

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);
    // Add the new node to the document.
    XmlElement root = doc.DocumentElement;
    doc.InsertBefore(xmldecl, root);
    // Display the modified XML document 

#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);
    // Add the new node to the document.
    XmlElement* root = doc->DocumentElement;
    doc->InsertBefore(xmldecl, root);
    // Display the modified XML document 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlDeclaration Class | XmlDeclaration Members | System.Xml Namespace

© 2016 Microsoft