Прочетете на английски Редактиране

Споделяне чрез


XDeclaration Constructors

Definition

Initializes a new instance of the XDeclaration class.

Overloads

XDeclaration(XDeclaration)

Initializes a new instance of the XDeclaration class from another XDeclaration object.

XDeclaration(String, String, String)

Initializes a new instance of the XDeclaration class with the specified version, encoding, and standalone status.

XDeclaration(XDeclaration)

Source:
XDeclaration.cs
Source:
XDeclaration.cs
Source:
XDeclaration.cs

Initializes a new instance of the XDeclaration class from another XDeclaration object.

C#
public XDeclaration(System.Xml.Linq.XDeclaration other);

Parameters

other
XDeclaration

The XDeclaration used to initialize this XDeclaration object.

Remarks

This constructor is primarily used internally to make a deep copy of an XML tree.

See also

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

XDeclaration(String, String, String)

Source:
XDeclaration.cs
Source:
XDeclaration.cs
Source:
XDeclaration.cs

Initializes a new instance of the XDeclaration class with the specified version, encoding, and standalone status.

C#
public XDeclaration(string version, string encoding, string standalone);
C#
public XDeclaration(string? version, string? encoding, string? standalone);

Parameters

version
String

The version of the XML, usually "1.0".

encoding
String

The encoding for the XML document.

standalone
String

A string containing "yes" or "no" that specifies whether the XML is standalone or requires external entities to be resolved.

Examples

The following example creates a document that contains a declaration.

C#
XDocument doc = new XDocument(  
    new XDeclaration("1.0", "utf-8", "yes"),  
    new XComment("This is a comment"),  
    new XElement("Root", "content")  
);  
doc.Save("Root.xml");  

Console.WriteLine(File.ReadAllText("Root.xml"));  

This example produces the following output:

XML
<?xml version="1.0" encoding="utf-8" standalone="yes"?>  
<!--This is a comment-->  
<Root>content</Root>  

See also

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0