Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Xml.​XmlTextWriter

Assembly: System.Xml.ReaderWriter

Inheritance: object → XmlWriter → XmlTextWriter

Implemented Interfaces

Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files containing XML data that conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations. We recommend that you use the <see cref="T:System.Xml.XmlWriter" /> class instead.

Properties

public IO.​Stream
BaseStream
Gets the underlying stream object.
public Formatting
Formatting
Indicates how the output is formatted.
public int
Indentation
Gets or sets how many IndentChars to write for each level in the hierarchy when <see cref="P:System.Xml.XmlTextWriter.Formatting" /> is set to <see langword="Formatting.Indented" /> .
public char
IndentChar
Gets or sets which character to use for indenting when <see cref="P:System.Xml.XmlTextWriter.Formatting" /> is set to <see langword="Formatting.Indented" /> .
public bool
Namespaces
Gets or sets a value indicating whether to do namespace support.
public char
QuoteChar
Gets or sets which character to use to quote attribute values.
public WriteState
WriteState
Gets the state of the writer.
public string
XmlLang
Gets the current <see langword="xml:lang" /> scope.
public XmlSpace
XmlSpace
Gets an <see cref="T:System.Xml.XmlSpace" /> representing the current <see langword="xml:space" /> scope.
Settings
Gets the <see cref="T:System.Xml.XmlWriterSettings" /> object used to create this <see cref="T:System.Xml.XmlWriter" /> instance.

Methods

public void
Close​()
Closes this stream and the underlying stream.
public void
Flush​()
Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
public string
LookupPrefix​(string ns)
Returns the closest prefix defined in the current namespace scope for the namespace URI.
Returns The matching prefix. Or <see langword="null" /> if no matching namespace URI is found in the current scope.
ns Namespace URI whose prefix you want to find.
public void
WriteBase64​(byte[] buffer, int index, int count)
Encodes the specified binary bytes as base64 and writes out the resulting text.
buffer Byte array to encode.
index The position within the buffer indicating the start of the bytes to write.
count The number of bytes to write.
public void
WriteBinHex​(byte[] buffer, int index, int count)
Encodes the specified binary bytes as binhex and writes out the resulting text.
buffer Byte array to encode.
index The position in the buffer indicating the start of the bytes to write.
count The number of bytes to write.
public void
WriteCData​(string text)
Writes out a &lt;![CDATA[...]]&gt; block containing the specified text.
text Text to place inside the CDATA block.
public void
WriteCharEntity​(char ch)
Forces the generation of a character entity for the specified Unicode character value.
ch Unicode character for which to generate a character entity.
public void
WriteChars​(char[] buffer, int index, int count)
Writes text one buffer at a time.
buffer Character array containing the text to write.
index The position in the buffer indicating the start of the text to write.
count The number of characters to write.
public void
WriteComment​(string text)
Writes out a comment &lt;!--...--&gt; containing the specified text.
text Text to place inside the comment.
public void
WriteDocType​(string name, string pubid, string sysid, string subset)
Writes the DOCTYPE declaration with the specified name and optional attributes.
name The name of the DOCTYPE. This must be non-empty.
pubid If non-null it also writes PUBLIC "pubid" "sysid" where <paramref name="pubid" /> and <paramref name="sysid" /> are replaced with the value of the given arguments.
sysid If <paramref name="pubid" /> is null and <paramref name="sysid" /> is non-null it writes SYSTEM "sysid" where <paramref name="sysid" /> is replaced with the value of this argument.
subset If non-null it writes [subset] where subset is replaced with the value of this argument.
public void
WriteEndAttribute​()
Closes the previous <see cref="M:System.Xml.XmlTextWriter.WriteStartAttribute(System.String,System.String,System.String)" /> call.
public void
WriteEndDocument​()
Closes any open elements or attributes and puts the writer back in the Start state.
public void
WriteEndElement​()
Closes one element and pops the corresponding namespace scope.
public void
WriteEntityRef​(string name)
Writes out an entity reference as <see langword="&amp;name;" /> .
name Name of the entity reference.
public void
WriteFullEndElement​()
Closes one element and pops the corresponding namespace scope.
public void
WriteName​(string name)
Writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation.
name Name to write.
public void
WriteNmToken​(string name)
Writes out the specified name, ensuring it is a valid <see langword="NmToken" /> according to the W3C XML 1.0 recommendation.
name Name to write.
public void
WriteProcessingInstruction​(string name, string text)
Writes out a processing instruction with a space between the name and text as follows: &lt;?name text?&gt;.
name Name of the processing instruction.
text Text to include in the processing instruction.
public void
WriteQualifiedName​(string localName, string ns)
Writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace.
localName The local name to write.
ns The namespace URI to associate with the name.
public void
WriteRaw​(char[] buffer, int index, int count)
Writes raw markup manually from a character buffer.
buffer Character array containing the text to write.
index The position within the buffer indicating the start of the text to write.
count The number of characters to write.
public void
WriteRaw​(string data)
Writes raw markup manually from a string.
data String containing the text to write.
public void
WriteStartAttribute​(string prefix, string localName, string ns)
Writes the start of an attribute.
prefix <see langword="Namespace" /> prefix of the attribute.
localName <see langword="LocalName" /> of the attribute.
ns <see langword="NamespaceURI" /> of the attribute.
public void
WriteStartDocument​()
Writes the XML declaration with the version "1.0".
public void
WriteStartDocument​(bool standalone)
Writes the XML declaration with the version "1.0" and the standalone attribute.
standalone If <see langword="true" /> , it writes "standalone=yes"; if <see langword="false" /> , it writes "standalone=no".
public void
WriteStartElement​(string prefix, string localName, string ns)
Writes the specified start tag and associates it with the given namespace and prefix.
prefix The namespace prefix of the element.
localName The local name of the element.
ns The namespace URI to associate with the element. If this namespace is already in scope and has an associated prefix then the writer automatically writes that prefix also.
public void
WriteString​(string text)
Writes the given text content.
text Text to write.
public void
WriteSurrogateCharEntity​(char lowChar, char highChar)
Generates and writes the surrogate character entity for the surrogate character pair.
lowChar The low surrogate. This must be a value between <see langword="0xDC00" /> and <see langword="0xDFFF" /> .
highChar The high surrogate. This must be a value between <see langword="0xD800" /> and <see langword="0xDBFF" /> .
public void
WriteWhitespace​(string ws)
Writes out the given white space.
ws The string of white space characters.
public void
Dispose​()
Inherited from XmlWriter
Releases all resources used by the current instance of the <see cref="T:System.Xml.XmlWriter" /> class.
protected void
Dispose​(bool disposing)
Inherited from XmlWriter
Releases the unmanaged resources used by the <see cref="T:System.Xml.XmlWriter" /> and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
FlushAsync​()
Inherited from XmlWriter
Asynchronously flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
Returns The task that represents the asynchronous <see langword="Flush" /> operation.
public void
WriteAttributes​(XmlReader reader, bool defattr)
Inherited from XmlWriter
When overridden in a derived class, writes out all the attributes found at the current position in the <see cref="T:System.Xml.XmlReader" /> .
reader The <see langword="XmlReader" /> from which to copy the attributes.
defattr <see langword="true" /> to copy the default attributes from the <see langword="XmlReader" /> ; otherwise, <see langword="false" /> .
WriteAttributesAsync​(XmlReader reader, bool defattr)
Inherited from XmlWriter
Asynchronously writes out all the attributes found at the current position in the <see cref="T:System.Xml.XmlReader" /> .
Returns The task that represents the asynchronous <see langword="WriteAttributes" /> operation.
reader The <see langword="XmlReader" /> from which to copy the attributes.
defattr <see langword="true" /> to copy the default attributes from the <see langword="XmlReader" /> ; otherwise, <see langword="false" /> .
public void
WriteAttributeString​(string localName, string value)
Inherited from XmlWriter
When overridden in a derived class, writes out the attribute with the specified local name and value.
localName The local name of the attribute.
value The value of the attribute.
public void
WriteAttributeString​(string localName, string ns, string value)
Inherited from XmlWriter
When overridden in a derived class, writes an attribute with the specified local name, namespace URI, and value.
localName The local name of the attribute.
ns The namespace URI to associate with the attribute.
value The value of the attribute.
public void
WriteAttributeString​(string prefix, string localName, string ns, string value)
Inherited from XmlWriter
When overridden in a derived class, writes out the attribute with the specified prefix, local name, namespace URI, and value.
prefix The namespace prefix of the attribute.
localName The local name of the attribute.
ns The namespace URI of the attribute.
value The value of the attribute.
WriteAttributeStringAsync​(string prefix, string localName, string ns, string value)
Inherited from XmlWriter
Asynchronously writes out the attribute with the specified prefix, local name, namespace URI, and value.
Returns The task that represents the asynchronous <see langword="WriteAttributeString" /> operation.
prefix The namespace prefix of the attribute.
localName The local name of the attribute.
ns The namespace URI of the attribute.
value The value of the attribute.
WriteBase64Async​(byte[] buffer, int index, int count)
Inherited from XmlWriter
Asynchronously encodes the specified binary bytes as Base64 and writes out the resulting text.
Returns The task that represents the asynchronous <see langword="WriteBase64" /> operation.
buffer Byte array to encode.
index The position in the buffer indicating the start of the bytes to write.
count The number of bytes to write.
WriteBinHexAsync​(byte[] buffer, int index, int count)
Inherited from XmlWriter
Asynchronously encodes the specified binary bytes as <see langword="BinHex" /> and writes out the resulting text.
Returns The task that represents the asynchronous <see langword="WriteBinHex" /> operation.
buffer Byte array to encode.
index The position in the buffer indicating the start of the bytes to write.
count The number of bytes to write.
WriteCDataAsync​(string text)
Inherited from XmlWriter
Asynchronously writes out a &lt;![CDATA[...]]&gt; block containing the specified text.
Returns The task that represents the asynchronous <see langword="WriteCData" /> operation.
text The text to place inside the CDATA block.
WriteCharEntityAsync​(char ch)
Inherited from XmlWriter
Asynchronously forces the generation of a character entity for the specified Unicode character value.
Returns The task that represents the asynchronous <see langword="WriteCharEntity" /> operation.
ch The Unicode character for which to generate a character entity.
WriteCharsAsync​(char[] buffer, int index, int count)
Inherited from XmlWriter
Asynchronously writes text one buffer at a time.
Returns The task that represents the asynchronous <see langword="WriteChars" /> operation.
buffer Character array containing the text to write.
index The position in the buffer indicating the start of the text to write.
count The number of characters to write.
WriteCommentAsync​(string text)
Inherited from XmlWriter
Asynchronously writes out a comment &lt;!--...--&gt; containing the specified text.
Returns The task that represents the asynchronous <see langword="WriteComment" /> operation.
text Text to place inside the comment.
WriteDocTypeAsync​(string name, string pubid, string sysid, string subset)
Inherited from XmlWriter
Asynchronously writes the DOCTYPE declaration with the specified name and optional attributes.
Returns The task that represents the asynchronous <see langword="WriteDocType" /> operation.
name The name of the DOCTYPE. This must be non-empty.
pubid If non-null it also writes PUBLIC "pubid" "sysid" where <paramref name="pubid" /> and <paramref name="sysid" /> are replaced with the value of the given arguments.
sysid If <paramref name="pubid" /> is <see langword="null" /> and <paramref name="sysid" /> is non-null it writes SYSTEM "sysid" where <paramref name="sysid" /> is replaced with the value of this argument.
subset If non-null it writes [subset] where subset is replaced with the value of this argument.
public void
WriteElementString​(string localName, string value)
Inherited from XmlWriter
Writes an element with the specified local name and value.
localName The local name of the element.
value The value of the element.
public void
WriteElementString​(string localName, string ns, string value)
Inherited from XmlWriter
Writes an element with the specified local name, namespace URI, and value.
localName The local name of the element.
ns The namespace URI to associate with the element.
value The value of the element.
public void
WriteElementString​(string prefix, string localName, string ns, string value)
Inherited from XmlWriter
Writes an element with the specified prefix, local name, namespace URI, and value.
prefix The prefix of the element.
localName The local name of the element.
ns The namespace URI of the element.
value The value of the element.
WriteElementStringAsync​(string prefix, string localName, string ns, string value)
Inherited from XmlWriter
Asynchronously writes an element with the specified prefix, local name, namespace URI, and value.
Returns The task that represents the asynchronous <see langword="WriteElementString" /> operation.
prefix The prefix of the element.
localName The local name of the element.
ns The namespace URI of the element.
value The value of the element.
WriteEndDocumentAsync​()
Inherited from XmlWriter
Asynchronously closes any open elements or attributes and puts the writer back in the Start state.
Returns The task that represents the asynchronous <see langword="WriteEndDocument" /> operation.
WriteEndElementAsync​()
Inherited from XmlWriter
Asynchronously closes one element and pops the corresponding namespace scope.
Returns The task that represents the asynchronous <see langword="WriteEndElement" /> operation.
WriteEntityRefAsync​(string name)
Inherited from XmlWriter
Asynchronously writes out an entity reference as <see langword="&amp;name;" /> .
Returns The task that represents the asynchronous <see langword="WriteEntityRef" /> operation.
name The name of the entity reference.
WriteFullEndElementAsync​()
Inherited from XmlWriter
Asynchronously closes one element and pops the corresponding namespace scope.
Returns The task that represents the asynchronous <see langword="WriteFullEndElement" /> operation.
WriteNameAsync​(string name)
Inherited from XmlWriter
Asynchronously writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).
Returns The task that represents the asynchronous <see langword="WriteName" /> operation.
name The name to write.
WriteNmTokenAsync​(string name)
Inherited from XmlWriter
Asynchronously writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).
Returns The task that represents the asynchronous <see langword="WriteNmToken" /> operation.
name The name to write.
public void
WriteNode​(XmlReader reader, bool defattr)
Inherited from XmlWriter
When overridden in a derived class, copies everything from the reader to the writer and moves the reader to the start of the next sibling.
reader The <see cref="T:System.Xml.XmlReader" /> to read from.
defattr <see langword="true" /> to copy the default attributes from the <see langword="XmlReader" /> ; otherwise, <see langword="false" /> .
public void
WriteNode​(XPathNavigator navigator, bool defattr)
Inherited from XmlWriter
Copies everything from the <see cref="T:System.Xml.XPath.XPathNavigator" /> object to the writer. The position of the <see cref="T:System.Xml.XPath.XPathNavigator" /> remains unchanged.
navigator The <see cref="T:System.Xml.XPath.XPathNavigator" /> to copy from.
defattr <see langword="true" /> to copy the default attributes; otherwise, <see langword="false" /> .
WriteNodeAsync​(XmlReader reader, bool defattr)
Inherited from XmlWriter
Asynchronously copies everything from the reader to the writer and moves the reader to the start of the next sibling.
Returns The task that represents the asynchronous <see langword="WriteNode" /> operation.
reader The <see cref="T:System.Xml.XmlReader" /> to read from.
defattr <see langword="true" /> to copy the default attributes from the <see langword="XmlReader" /> ; otherwise, <see langword="false" /> .
WriteNodeAsync​(XPathNavigator navigator, bool defattr)
Inherited from XmlWriter
Asynchronously copies everything from the <see cref="T:System.Xml.XPath.XPathNavigator" /> object to the writer. The position of the <see cref="T:System.Xml.XPath.XPathNavigator" /> remains unchanged.
Returns The task that represents the asynchronous <see langword="WriteNode" /> operation.
navigator The <see cref="T:System.Xml.XPath.XPathNavigator" /> to copy from.
defattr <see langword="true" /> to copy the default attributes; otherwise, <see langword="false" /> .
WriteProcessingInstructionAsync​(string name, string text)
Inherited from XmlWriter
Asynchronously writes out a processing instruction with a space between the name and text as follows: &lt;?name text?&gt;.
Returns The task that represents the asynchronous <see langword="WriteProcessingInstruction" /> operation.
name The name of the processing instruction.
text The text to include in the processing instruction.
WriteQualifiedNameAsync​(string localName, string ns)
Inherited from XmlWriter
Asynchronously writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace.
Returns The task that represents the asynchronous <see langword="WriteQualifiedName" /> operation.
localName The local name to write.
ns The namespace URI for the name.
WriteRawAsync​(char[] buffer, int index, int count)
Inherited from XmlWriter
Asynchronously writes raw markup manually from a character buffer.
Returns The task that represents the asynchronous <see langword="WriteRaw" /> operation.
buffer Character array containing the text to write.
index The position within the buffer indicating the start of the text to write.
count The number of characters to write.
WriteRawAsync​(string data)
Inherited from XmlWriter
Asynchronously writes raw markup manually from a string.
Returns The task that represents the asynchronous <see langword="WriteRaw" /> operation.
data String containing the text to write.
public void
WriteStartAttribute​(string localName)
Inherited from XmlWriter
Writes the start of an attribute with the specified local name.
localName The local name of the attribute.
public void
WriteStartAttribute​(string localName, string ns)
Inherited from XmlWriter
Writes the start of an attribute with the specified local name and namespace URI.
localName The local name of the attribute.
ns The namespace URI of the attribute.
WriteStartDocumentAsync​()
Inherited from XmlWriter
Asynchronously writes the XML declaration with the version "1.0".
Returns The task that represents the asynchronous <see langword="WriteStartDocument" /> operation.
WriteStartDocumentAsync​(bool standalone)
Inherited from XmlWriter
Asynchronously writes the XML declaration with the version "1.0" and the standalone attribute.
Returns The task that represents the asynchronous <see langword="WriteStartDocument" /> operation.
standalone If <see langword="true" /> , it writes "standalone=yes"; if <see langword="false" /> , it writes "standalone=no".
public void
WriteStartElement​(string localName)
Inherited from XmlWriter
When overridden in a derived class, writes out a start tag with the specified local name.
localName The local name of the element.
public void
WriteStartElement​(string localName, string ns)
Inherited from XmlWriter
When overridden in a derived class, writes the specified start tag and associates it with the given namespace.
localName The local name of the element.
ns The namespace URI to associate with the element. If this namespace is already in scope and has an associated prefix, the writer automatically writes that prefix also.
WriteStartElementAsync​(string prefix, string localName, string ns)
Inherited from XmlWriter
Asynchronously writes the specified start tag and associates it with the given namespace and prefix.
Returns The task that represents the asynchronous <see langword="WriteStartElement" /> operation.
prefix The namespace prefix of the element.
localName The local name of the element.
ns The namespace URI to associate with the element.
WriteStringAsync​(string text)
Inherited from XmlWriter
Asynchronously writes the given text content.
Returns The task that represents the asynchronous <see langword="WriteString" /> operation.
text The text to write.
WriteSurrogateCharEntityAsync​(char lowChar, char highChar)
Inherited from XmlWriter
Asynchronously generates and writes the surrogate character entity for the surrogate character pair.
Returns The task that represents the asynchronous <see langword="WriteSurrogateCharEntity" /> operation.
lowChar The low surrogate. This must be a value between 0xDC00 and 0xDFFF.
highChar The high surrogate. This must be a value between 0xD800 and 0xDBFF.
public void
WriteValue​(bool value)
Inherited from XmlWriter
Writes a <see cref="T:System.Boolean" /> value.
value The <see cref="T:System.Boolean" /> value to write.
public void
WriteValue​(DateTime value)
Inherited from XmlWriter
Writes a <see cref="T:System.DateTime" /> value.
value The <see cref="T:System.DateTime" /> value to write.
public void
WriteValue​(DateTimeOffset value)
Inherited from XmlWriter
Writes a <see cref="T:System.DateTimeOffset" /> value.
value The <see cref="T:System.DateTimeOffset" /> value to write.
public void
WriteValue​(decimal value)
Inherited from XmlWriter
Writes a <see cref="T:System.Decimal" /> value.
value The <see cref="T:System.Decimal" /> value to write.
public void
WriteValue​(double value)
Inherited from XmlWriter
Writes a <see cref="T:System.Double" /> value.
value The <see cref="T:System.Double" /> value to write.
public void
WriteValue​(int value)
Inherited from XmlWriter
Writes a <see cref="T:System.Int32" /> value.
value The <see cref="T:System.Int32" /> value to write.
public void
WriteValue​(long value)
Inherited from XmlWriter
Writes a <see cref="T:System.Int64" /> value.
value The <see cref="T:System.Int64" /> value to write.
public void
WriteValue​(object value)
Inherited from XmlWriter
Writes the object value.
value The object value to write. Note With the release of the .NET Framework 3.5, this method accepts <see cref="T:System.DateTimeOffset" /> as a parameter.
public void
WriteValue​(Single value)
Inherited from XmlWriter
Writes a single-precision floating-point number.
value The single-precision floating-point number to write.
public void
WriteValue​(string value)
Inherited from XmlWriter
Writes a <see cref="T:System.String" /> value.
value The <see cref="T:System.String" /> value to write.
WriteWhitespaceAsync​(string ws)
Inherited from XmlWriter
Asynchronously writes out the given white space.
Returns The task that represents the asynchronous <see langword="WriteWhitespace" /> operation.
ws The string of white space characters.
DisposeAsync​()
Inherited from XmlWriter
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
Returns A task that represents the asynchronous dispose operation.
DisposeAsyncCore​()
Inherited from XmlWriter
Performs application-defined tasks associated with freeing, releasing, or resetting managed resources asynchronously.
Returns A task that represents the asynchronous dispose operation.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object