Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Nodes Inheritance: CloudNimble.Text.Xml.Nodes.XmlNode

Syntax

Summary

Represents a mutable XML declaration. This class cannot be inherited.

Usage

XmlDeclarationNode is the XML declaration, <?xml version="1.0" encoding="utf-8"?>, as a node you can set up and write. Version defaults to 1.0, Encoding to utf-8, and Standalone to null, which leaves standalone out. You seldom need it. A Utf8XmlWriter writes a declaration by itself unless XmlWriterOptions.OmitXmlDeclaration is true, as the first half of this example shows. Use the node when you want to state the declaration yourself, for example to write standalone="yes". Write it first, to a writer that omits its own declaration.
The code produces the following output:
View the complete sample on GitHub

Remarks

The read-only XmlDocument reports its declaration as an XmlDeclarationInfo instead. XmlDeclarationNode.WriteTo writes XmlDeclarationNode.Version and XmlDeclarationNode.Encoding as they are, without validating them.

Considerations

  • WriteTo writes the declaration and records it with the writer, so the writer doesn’t add a second one, whatever OmitXmlDeclaration is set to.
  • The node must be written before anything else. It can’t be added to an element’s Children; that throws an XmlException.
  • Version and Encoding are written as they are, without validation. XmlEssentials writes UTF-8 only, so leave Encoding at utf-8. Setting Version to 1.1 changes the declaration, not the writer; set XmlWriterOptions.Version as well.
  • XmlNode.Parse never returns this node, and a tree has no document node to hold it. The declaration of a parsed document is XmlDocument.Declaration, an XmlDeclarationInfo.
  • This is the only node type whose ValueKind is XmlDeclaration.

Constructors

.ctor

Syntax

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

Encoding

Gets or sets the encoding name that the declaration states.

Syntax

Property Value

Type: string The value of the encoding pseudo-attribute. The default is utf-8.

NamespaceUri Inherited Virtual

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Gets or sets the namespace URI of this node.

Syntax

Property Value

Type: string? The namespace URI of the node. An element or an attribute in no namespace gives an empty string. For a node that is not an element or an attribute, the value is always null, and setting it has no effect.

Parent Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Gets the parent of this node.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Nodes.XmlNode? The element that holds this node as a child or as an attribute, or null if this node has no parent.

Standalone

Gets or sets the standalone document declaration.

Syntax

Property Value

Type: bool? true to write standalone="yes"; false to write standalone="no"; null to omit the standalone pseudo-attribute. The default is null.

ValueKind Override

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlValueKind

ValueKind Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, gets the kind of this node.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlValueKind One of the enumeration values that indicates the kind of this node.

Version

Gets or sets the XML version that the declaration states.

Syntax

Property Value

Type: string The value of the version pseudo-attribute. The default is 1.0.

Methods

DeepClone Override

Syntax

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode

DeepClone Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, creates a new instance of the node. All children and attributes are recursively cloned.

Syntax

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode A new cloned instance of the current node. The clone has no parent.

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

Parse Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses a string that holds a single XML document into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the document element.

Exceptions

Remarks

Comments inside the document element are kept. The XML declaration and any comments or processing instructions outside the document element are not part of the returned tree.

Parse Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses a span of UTF-8 bytes that holds a single XML document into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the document element.

Exceptions

Remarks

Comments inside the document element are kept. The XML declaration and any comments or processing instructions outside the document element are not part of the returned tree.

ParseValue Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses one XML element (including its attributes and descendants) from the provided reader into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the element (and nested nodes) read from the reader.

Exceptions

Remarks

When this method returns, the reader is positioned on the end tag of the element, or on the element itself if it is an empty-element tag. Comments are kept only if the reader reports them.

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

SetParent Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Sets the parent pointer.

Syntax

Parameters

ToString Override

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Converts the current instance to a string that holds its XML markup.

Syntax

Returns

Type: string The XML markup of this node, including its attributes and descendants. No XML declaration is added.

Exceptions

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?

WriteTo Override

Syntax

Parameters

WriteTo Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, writes this node to the provided writer as XML.

Syntax

Parameters

Exceptions

  • CloudNimble.Text.Xml.XmlDeclarationInfo
  • CloudNimble.Text.Xml.XmlWriterOptions
  • CloudNimble.Text.Xml.Utf8XmlWriter
  • CloudNimble.Text.Xml.XmlDocument
  • CloudNimble.Text.Xml.Nodes.XmlNode