XmlDeclaration.Standalone 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置独立特性的值。
public:
property System::String ^ Standalone { System::String ^ get(); void set(System::String ^ value); };
public string Standalone { get; set; }
member this.Standalone : string with get, set
Public Property Standalone As String
属性值
如果 XML 文档所需要的所有实体声明都包含在文档内,则有效值为 yes
,或者如果需要外部文档类型定义 (DTD),则为 no
。 如果 XML 声明中没有独立特性,该属性将返回 String.Empty。
示例
以下示例创建一个 XmlDeclaration
节点并将其添加到 XML 文档。
#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 = gcnew XmlDocument;
String^ xmlString = "<book><title>Oberon's Legacy</title></book>";
doc->Load( gcnew StringReader( xmlString ) );
// Create an XML declaration.
XmlDeclaration^ xmldecl;
xmldecl = doc->CreateXmlDeclaration( "1.0", nullptr, nullptr );
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 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);
}
}
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)
xmldecl.Encoding="UTF-8"
xmldecl.Standalone="yes"
' Add the new node to the document.
Dim root as XmlElement = doc.DocumentElement
doc.InsertBefore(xmldecl, root)
' Display the modified XML document
Console.WriteLine(doc.OuterXml)
end sub
end class