XML System.Xml [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.IDisposable The class writes XML data to a stream, file, text reader, or string. It supports the W3C Extensible Markup Language (XML) 1.0 (fourth edition) and Namespaces in XML 1.0 (third edition) recommendations. The members of the class enable you to: Verify that the characters are legal XML characters and that element and attribute names are valid XML names. Verify that the XML document is well-formed. Encode binary bytes as Base64 or BinHex, and write out the resulting text. Pass values by using common language runtime types instead of strings, to avoid having to manually perform value conversions. Write multiple documents to one output stream. Write valid names, qualified names, and name tokens. In this section: Creating an XML writer
Specifying the output format
Data conformance
Writing elements
Writing attributes
Handling namespaces
Writing typed data
Closing the XML writer
Asynchronous programming
Security considerations

Creating an XML writer

To create an instance, use the method. To specify the set of features you want to enable on the XML writer, pass an to the method. Otherwise, default settings are used. See the reference pages for details.

Specifying the output format

The class includes several properties that control how output is formatted: Property Description Specifies the text encoding to use. The default is Encoding.UTF8. Indicates whether to indent elements. The default is false (no indentation). Specifies the character string to use when indenting. The default is two spaces. Specifies the character string to use for line breaks. The default is \r\n (carriage return, line feed). Specifies how to handle newline characters. Indicates whether to write attributes on a new line. should be set to true when using this property. The default is false. Indicates whether to write an XML declaration. The default is false. The and properties control how insignificant white space is formatted. For example, to indent element nodes: code reference: XmlWriter_v2#8 Use the to write each attribute on a new line with one extra level of indentation: code reference: XmlWriter_v2#9

Data conformance

An XML writer uses two properties from the class to check for data conformance: The property instructs the XML writer to check characters and throw an exception if any characters are outside the legal range, as defined by the W3C. The property configures the XML writer to check that the stream being written complies with the rules for a well-formed XML 1.0 document or document fragment, as defined by the W3C. The three conformance levels are described in the following table. The default is . For details, see the property and the enumeration. Level Description The XML output conforms to the rules for a well-formed XML 1.0 document and can be processed by any conforming processor. The XML output conforms to the rules for a well-formed XML 1.0 document fragment. The XML writer determines which level of conformation checking to apply (document or fragment) based on the incoming data.

Writing elements

You can use the following methods to write element nodes. For examples, see the methods listed. Use To Write an entire element node, including a string value. To write an element value by using multiple method calls. For example, you can call to write a typed value, to write a character entity, to write an attribute, or you can write a child element. This is a more sophisticated version of the method. To close the element, you call the or method. To copy an element node found at the current position of an or object. When called, it copies everything from the source object to the instance.

Writing attributes

You can use the following methods to write attributes on element nodes. These methods can also be used to create namespace declarations on an element, as discussed in the next section. Use To To write an entire attribute node, including a string value. To write the attribute value using multiple method calls. For example, you can call to write a typed value. This is a more sophisticated version of the method. To close the element, you call the method. To copy all the attributes found at the current position of an object. The attributes that are written depend on the type of node the reader is currently positioned on: For an attribute node, it writes the current attribute, and then the rest of the attributes until the element closing tag. For an element node, it writes all attributes contained by the element. For an XML declaration node, it writes all the attributes in the declaration. For all other node types, the method throws an exception.

Handling namespaces

Namespaces are used to qualify element and attribute names in an XML document. Namespace prefixes associate elements and attributes with namespaces, which are in turn associated with URI references. Namespaces create element and attribute name uniqueness in an XML document. The maintains a namespace stack that corresponds to all the namespaces defined in the current namespace scope. When writing elements and attributes you can utilize namespaces in the following ways: Declare namespaces manually by using the method. This can be useful when you know how to best optimize the number of namespace declarations. For an example, see the method. Override the current namespace declaration with a new namespace. In the following code, the method changes the namespace URI for the "x" prefix from "123" to "abc". code reference: XmlWriter_v2#18 The code generates the following XML string: <x:root xmlns:x="123"> <item xmlns:x="abc" /> </x:root> Specify a namespace prefix when writing attributes or elements. Many of the methods used to write element and attributes enable you to do this. For example, the method writes a start tag and associates it with a specified namespace and prefix.

Writing typed data

The method accepts a common language runtime (CLR) object, converts the input value to its string representation according to XML schema definition language (XSD) data type conversion rules, and writes it out by using the method. This is easier than using the methods in the class to convert the typed data to a string value before writing it out. When writing to text, the typed value is serialized to text by using the rules for that schema type. For default XSD data types that correspond to CLR types, see the method. The can also be used to write to an XML data store. For example, the class can create an object to create nodes for an object. If the data store has schema information available to it, the method throws an exception if you try to convert to a type that is not allowed.If the data store does not have schema information available to it, the method treats all values as an xsd:anySimpleType type.

Closing the XML writer

When you use methods to output XML, the elements and attributes are not written until you call the method. For example, if you are using to populate an object, you won't be able to see the written elements and attributes in the target document until you close the instance.

Asynchronous programming

Most of the methods have asynchronous counterparts that have "Async" at the end of their method names. For example, the asynchronous equivalent of is . For the method, which doesn't have an asynchronous counterpart, convert the return value to a string and use the method instead.

Security considerations

Consider the following when working with the class: Exceptions thrown by the can disclose path information that you do not want bubbled up to the app. Your app must catch exceptions and process them appropriately. does not validate any data that is passed to the or method. You should not pass arbitrary data to these methods.
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files that contain XML data.
Constructor 1.0.5000.0 2.0.0.0 4.0.0.0 To be added. Initializes a new instance of the class. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void Any elements or attributes left open are automatically closed. When you use the methods to output XML, the elements and attributes will not be written until you call the method. For example, if you are using the XmlWriter to populate an , until you close the , you will not be able to observe the written elements and attributes in the target document. When overridden in a derived class, closes this stream and the underlying stream. 0 Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter When you use this overload, an object with the following default settings is used to create the XML writer: Setting Default true false false Two spaces (no removal) \r\n (carriage return, new line) false false true If you want to specify the features to support on the created writer, use an overload that takes an object as one of its arguments, and pass in an object with your custom settings. Also, XmlWriter always writes a Byte Order Mark (BOM) to the underlying data stream; however, some streams must not have a BOM. To omit the BOM, create a new object and set the Encoding property to be a new object with the Boolean value in the constructor set to false. Creates a new instance using the specified stream. An object. The stream to which you want to write. The writes XML 1.0 text syntax and appends it to the specified stream. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter When you use this overload, an object with default settings is used to create the XML writer. Setting Default true false false Two spaces (no removal) \r\n (carriage return, new line) false false true If you want to specify the features to support on the created writer, use an overload that takes an object as one of its arguments, and pass in an object with your custom settings. Creates a new instance using the specified . An object. The to which you want to write. The writes XML 1.0 text syntax and appends it to the specified . Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter When you use this overload, an object with default settings is used to create the XML writer. Setting Default true false false Two spaces (no removal) \r\n (carriage return, new line) false false true If you want to specify the features to support on the created XML writer, use an overload that takes an object as one of its arguments, and pass in a object with your custom settings. Creates a new instance using the specified filename. An object. The file to which you want to write. The creates a file at the specified path and writes to it in XML 1.0 text syntax. The must be a file system path. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter When you use this overload, an object with default settings is used to create the XML writer. Setting Default true false false Two spaces (no removal) \r\n (carriage return, new line) false false true If you want to specify the features to support on the created XML writer, use an overload that takes an object as one of its arguments, and pass in a object with your custom settings. Creates a new instance using the specified . An object. The to which to write to. Content written by the is appended to the . Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter This method allows you add features to an underlying object. The underlying object can be an object created by the method, or an object created using the implementation. When you use this overload, an object with default settings is used to create the XML writer. Setting Default true false false Two spaces (no removal) \r\n (carriage return, new line) false false true If you want to specify the features to support on the created XML writer, use an overload that takes an object as one of its arguments, and pass in a object with your custom settings. Creates a new instance using the specified object. An object that is wrapped around the specified object. The object that you want to use as the underlying writer. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter XmlWriter always writes a Byte Order Mark (BOM) to the underlying data stream; however, some streams must not have a BOM. To omit the BOM, create a new object and set the Encoding property to be a new object with the Boolean value in the constructor set to false. Creates a new instance using the stream and object. An object. The stream to which you want to write. The writes XML 1.0 text syntax and appends it to the specified stream. The object used to configure the new instance. If this is null, a with default settings is used. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter To be added. Creates a new instance using the and objects. An object. The to which you want to write. The writes XML 1.0 text syntax and appends it to the specified . The object used to configure the new instance. If this is null, a with default settings is used. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter To be added. Creates a new instance using the filename and object. An object. The file to which you want to write. The creates a file at the specified path and writes to it in XML 1.0 text syntax. The must be a file system path. The object used to configure the new instance. If this is null, a with default settings is used. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter To be added. Creates a new instance using the and objects. An object. The to which to write to. Content written by the is appended to the . The object used to configure the new instance. If this is null, a with default settings is used. Method 2.0.0.0 4.0.0.0 System.Xml.XmlWriter This method allows you add additional features to an underlying object. The underlying object can be an object created by the method, or an object created using the implementation. Creates a new instance using the specified and objects. An object that is wrapped around the specified object. The object that you want to use as the underlying writer. The object used to configure the new instance. If this is null, a with default settings is used. Method 4.0.0.0 System.Void To be added. Releases all resources used by the current instance of the class. Method 2.0.0.0 4.0.0.0 System.Void To be added. Releases the unmanaged resources used by the and optionally releases the managed resources. true to release both managed and unmanaged resources; false to release only unmanaged resources. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void This is called instead of when you want to write more to the underlying stream without losing what is still in the buffer. For the asynchronous version of this method, see . When overridden in a derived class, flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream. The task that represents the asynchronous Flush operation. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.String As described above. This method must be overridden in order to provide the functionality described above, as there is no default implementation. is or . When overridden in a derived class, returns the closest prefix defined in the current namespace scope for the namespace URI. The matching prefix or null if no matching namespace URI is found in the current scope. The namespace URI whose prefix you want to find. 0 Property 2.0.0.0 4.0.0.0 System.Xml.XmlWriterSettings To be added. The class is used to specify the set of features to support on the created writer instance. The object returned by the property cannot be modified. Any attempt to change individual settings results in an exception being thrown. Gets the object used to create this instance. Method System.Void This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface. For a description of this member, see . 2.0.0.0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The is . is not positioned on a node of , , or . If the reader is positioned on an element node WriteAttributes copies all the contained attributes. If the reader is positioned on an attribute node, this method writes the current attribute, then the rest of the attributes until the element closing tag. If the reader is positioned on an XmlDeclaration node, this method writes all the attributes in the declaration. If the reader is positioned on any other node type this method throws an . If this method is called using , to ensure well-formed XML any content (which has been expanded from the entities) that could result in an invalid document is replaced when written. For example, if an attribute includes an &gt; entity that has been expanded, to ensure a well-formed document the expanded > is replaced when written out with &gt;. For the asynchronous version of this method, see . When overridden in a derived class, writes out all the attributes found at the current position in the . The XmlReader from which to copy the attributes. true to copy the default attributes from the XmlReader; otherwise, false. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out all the attributes found at the current position in the . The task that represents the asynchronous WriteAttributes operation. The XmlReader from which to copy the attributes. true to copy the default attributes from the XmlReader; otherwise, false. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or . The is not . The value of the attribute. WriteAttributeString does the following: If the attribute value includes double or single quotes, they are replaced with &quot; and &apos; respectively. If writing an xml:space attribute, the writer verifies the attribute value is valid. (Valid values are preserve or default.) If writing an xml:lang attribute, the writer does not verify that the attribute value is valid according to the W3C XML 1.0 recommendation. For the asynchronous version of this method, see . When overridden in a derived class, writes out the attribute with the specified local name and value. The local name of the attribute. The value of the attribute. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or . The is not . The namespace URI to associate with the attribute. The value of the attribute. This method writes out the attribute with a user defined namespace prefix and associates it with the given namespace. If is "xmlns" then this method also treats this as a namespace declaration. In this case, the argument can be null. WriteAttributeString does the following: If the attribute value includes double or single quotes, they are replaced with &quot; and &apos; respectively. If writing an xml:space attribute, the writer verifies the attribute value is valid. (Valid values are preserve or default.) If writing an xml:lang attribute, the writer does not verify that the attribute value is valid according to the W3C XML 1.0 recommendation. For the asynchronous version of this method, see . When overridden in a derived class, writes an attribute with the specified local name, namespace URI, and value. The local name of the attribute. The namespace URI to associate with the attribute. The value of the attribute. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or . The is not . The local name of the attribute. The namespace URI of the attribute. The value of the attribute. This method writes out the attribute with a user defined namespace prefix and associates it with the given namespace. If the prefix is "xmlns" then this method also treats this as a namespace declaration and associates the declared prefix with the namespace URI provided in the given attribute value. In this case the argument can be null. WriteAttributeString does the following: If the attribute value includes double or single quotes, they are replaced with &quot; and &apos; respectively. If writing an xml:space attribute, the writer verifies the attribute value is valid. (Valid values are preserve or default.) If writing an xml:lang attribute, the writer does not verify that the attribute value is valid according to the W3C XML 1.0 recommendation. For the asynchronous version of this method, see . When overridden in a derived class, writes out the attribute with the specified prefix, local name, namespace URI, and value. The namespace prefix of the attribute. The local name of the attribute. The namespace URI of the attribute. The value of the attribute. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out the attribute with the specified prefix, local name, namespace URI, and value. The task that represents the asynchronous WriteAttributeString operation. The namespace prefix of the attribute. The local name of the attribute. The namespace URI of the attribute. The value of the attribute. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The buffer length minus is less than . or is less than zero. The is . For example, the byte buffer may contain the binary contents of a GIF image. This clearly would not be valid XML. The Base64 encoding is designed to represent arbitrary byte sequences in a text form comprised of the 65 US-ASCII characters ([A-Za-z0-9+/=]) where each character encodes 6 bits of the binary data. For more information, see Requests for Comments (RFC) 1521 located on the Request for Comments Web site at http://www.rfc-editor.org/. For the asynchronous version of this method, see . When overridden in a derived class, encodes the specified binary bytes as Base64 and writes out the resulting text. Byte array to encode. The position in the buffer indicating the start of the bytes to write. The number of bytes to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously encodes the specified binary bytes as Base64 and writes out the resulting text. The task that represents the asynchronous WriteBase64 operation. Byte array to encode. The position in the buffer indicating the start of the bytes to write. The number of bytes to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The buffer length minus is less than . or is less than zero. The is . For the asynchronous version of this method, see . When overridden in a derived class, encodes the specified binary bytes as BinHex and writes out the resulting text. Byte array to encode. The position in the buffer indicating the start of the bytes to write. The number of bytes to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously encodes the specified binary bytes as BinHex and writes out the resulting text. The task that represents the asynchronous WriteBinHex operation. Byte array to encode. The position in the buffer indicating the start of the bytes to write. The number of bytes to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The text would result in a non-well formed XML document. The is . If is either null or String.Empty, this method writes an empty CDATA block, for example <![CDATA[]]>. For the asynchronous version of this method, see . When overridden in a derived class, writes out a <![CDATA[...]]> block containing the specified text. The text to place inside the CDATA block. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out a <![CDATA[...]]> block containing the specified text. The task that represents the asynchronous WriteCData operation. The text to place inside the CDATA block. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The character is in the surrogate pair character range, 0xd800 - 0xdfff, or the text would result in a non-well formed XML document. The is . This method writes the Unicode character in hexadecimal character entity reference format. For the asynchronous version of this method, see . When overridden in a derived class, forces the generation of a character entity for the specified Unicode character value. The Unicode character for which to generate a character entity. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously forces the generation of a character entity for the specified Unicode character value. The task that represents the asynchronous WriteCharEntity operation. The Unicode character for which to generate a character entity. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The buffer length minus is less than . or is less than zero. The is . This method can be used to write large amounts of text one buffer at a time. Special handling must be done to ensure the WriteChars method does not split surrogate pair characters across multiple buffer writes. The XML specification defines the valid ranges for surrogate pairs. For the asynchronous version of this method, see . When overridden in a derived class, writes text one buffer at a time. Character array containing the text to write. The position in the buffer indicating the start of the text to write. The number of characters to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes text one buffer at a time. The task that represents the asynchronous WriteChars operation. Character array containing the text to write. The position in the buffer indicating the start of the text to write. The number of characters to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The text would result in a non-well formed XML document. The is . If is either null or String.Empty, this method writes a comment with no data content, for example <!---->. If contains an invalid sequence of two dashes "--" the can either throw an ( objects) or insert a space between the dashes "- -" so that the text is a valid XML comment ( objects created by the method). For the asynchronous version of this method, see . When overridden in a derived class, writes out a comment <!--...--> containing the specified text. Text to place inside the comment. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out a comment <!--...--> containing the specified text. The task that represents the asynchronous WriteComment operation. Text to place inside the comment. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or . -or- The value for would result in invalid XML. This method was called outside the prolog (after the root element). This method does not check for invalid characters in , or . It also does not check that the internal subset is well-formed. The does not validate the data that is passed to the method. You should not pass arbitrary data to this method. For the asynchronous version of this method, see . When overridden in a derived class, writes the DOCTYPE declaration with the specified name and optional attributes. The name of the DOCTYPE. This must be non-empty. If non-null it also writes PUBLIC "pubid" "sysid" where and are replaced with the value of the given arguments. If is null and is non-null it writes SYSTEM "sysid" where is replaced with the value of this argument. If non-null it writes [subset] where subset is replaced with the value of this argument. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the DOCTYPE declaration with the specified name and optional attributes. The task that represents the asynchronous WriteDocType operation. The name of the DOCTYPE. This must be non-empty. If non-null it also writes PUBLIC "pubid" "sysid" where and are replaced with the value of the given arguments. If is null and is non-null it writes SYSTEM "sysid" where is replaced with the value of this argument. If non-null it writes [subset] where subset is replaced with the value of this argument. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . The value of the element. For the asynchronous version of this method, see . Writes an element with the specified local name and value. The local name of the element. The value of the element. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . The value of the element. For the asynchronous version of this method, see . Writes an element with the specified local name, namespace URI, and value. The local name of the element. The namespace URI to associate with the element. The value of the element. 0 Method 2.0.0.0 4.0.0.0 System.Void For the asynchronous version of this method, see . Writes an element with the specified prefix, local name, namespace URI, and value. The prefix of the element. The local name of the element. The namespace URI of the element. The value of the element. Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes an element with the specified prefix, local name, namespace URI, and value. The task that represents the asynchronous WriteElementString operation. The prefix of the element. The local name of the element. The namespace URI of the element. The value of the element. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is not . If you call WriteStartAttribute, you can close the attribute with this method. You can also close the attribute by calling WriteStartAttribute again, calling , or calling . When you use the methods to output XML, the elements and attributes will not be written until you call the method. For example, if you are using the XmlWriter to populate an , until you close the , you will not be able to observe the written elements and attributes in the target document. For the asynchronous version of this method, see . When overridden in a derived class, closes the previous call. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously closes the previous call. The task that represents the asynchronous WriteEndAttribute operation. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The current instance is in the wrong , or the document does not have a root element. When you use the methods to output XML, the elements and attributes will not be written until you call the method. For example, if you are using the XmlWriter to populate an , until you close the , you will not be able to observe the written elements and attributes in the target document. For the asynchronous version of this method, see . When overridden in a derived class, closes any open elements or attributes and puts the writer back in the Start state. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously closes any open elements or attributes and puts the writer back in the Start state. The task that represents the asynchronous WriteEndDocument operation. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void No element was open, or the is . If the element contains no content, a short end tag "/>" is written; otherwise, a full end tag is written. When you use the methods to output XML, the elements and attributes will not be written until you call the method. For example, if you are using the XmlWwriter to populate an , until you close the , you will not be able to observe the written elements and attributes in the target document. For the asynchronous version of this method, see . When overridden in a derived class, closes one element and pops the corresponding namespace scope. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously closes one element and pops the corresponding namespace scope. The task that represents the asynchronous WriteEndElement operation. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is either or . For the asynchronous version of this method, see . When overridden in a derived class, writes out an entity reference as &name;. The name of the entity reference. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out an entity reference as &name;. The task that represents the asynchronous WriteEntityRef operation. The name of the entity reference. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void No element was open, or the is . This method always writes the full end tag. This is useful when dealing with elements that must include a full end tag. For example, browsers expect HTML script blocks to be closed with "</script>". For the asynchronous version of this method, see . When overridden in a derived class, closes one element and pops the corresponding namespace scope. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously closes one element and pops the corresponding namespace scope. The task that represents the asynchronous WriteFullEndElement operation. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or ; or is not a valid XML Name. The is . If is set to true, WriteName also checks that the name is also valid according to the W3C Namespaces in XML recommendation. For the asynchronous version of this method, see . When overridden in a derived class, writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name). The name to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name). The task that represents the asynchronous WriteName operation. The name to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or ; or is not a valid XML Nmtoken. The is . For the asynchronous version of this method, see . When overridden in a derived class, writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1.0 recommendation (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name). The name to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1.0 recommendation (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name). The task that represents the asynchronous WriteNmToken operation. The name to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The is . The following example uses a and a to copy an XML file, specified in the command line, to the console. using System; using System.Xml; public class Copier { public static void Main(string[] args) { XmlTextReader xtReader = new XmlTextReader(args[0]); XmlTextWriter xtWriter = new XmlTextWriter(Console.Out); xtWriter.WriteNode(xtReader, false); xtWriter.Close(); xtReader.Close(); } } The following table shows the supported node types for this method. NodeType WriteNode Behavior None Writes out all the nodes irrespective of type. That is, the writer consumes the and writes out all the nodes read including attributes, processing instructions, comments, and so on. This situation occurs when the is in an initial state. (The property returns ReaderState.Initial). Element Writes out the element node and any attribute nodes. Attribute No operation. Use or instead. Text Writes out the text node. CDATA Writes out the CDATA section node. EntityReference Writes out the entity reference node. ProcessingInstruction Writes out the processing instruction node. Comment Writes out the comment node. DocumentType Writes out the document type node. SignificantWhitespace Writes out the significant white space node. Whitespace Writes out the white space node. EndElement Writes out the end element tag. EndEntity No operation. XmlDeclaration Writes out the XML declaration node. If the reader is in the initial state, this method moves the reader to the end of file. If the reader is already at the end of file or in a closed state, this method is non-operational. The following C# code copies an entire XML input document to the console: XmlReader reader = XmlReader.Create(myfile); XmlWriter writer = XmlWriter.Create(Console.Out); writer.WriteNode(reader, false); If you have moved off the root node and are positioned elsewhere in the document the following C# example correctly writes out the nodes. XmlReader reader = XmlReader.Create(myfile); reader.Read(); // Read PI reader.Read(); // Read Comment reader.Read(); // Read DOCType XmlWriter writer = XmlWriter.Create(Console.Out); while (!reader.EOF){ writer.WriteNode(reader, false); } If the reader is configured to return white space and the writer has is configured to indent output, WriteNode may produce strange output. You will essentially be getting double formatting. For the asynchronous version of this method, see . 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. The to read from. true to copy the default attributes from the XmlReader; otherwise, false. 0 Method 2.0.0.0 4.0.0.0 System.Void The following table shows the supported XPath node types for this method. XPathNodeType WriteNode Behavior Root Writes out all the nodes irrespective of type. That is, the writer consumes the and writes out all the nodes from the root node (including attributes, processing instructions, comments and so on.) Element Writes out the element node and any attribute nodes. Attribute No operation. Use or instead. Text Writes out the text node. Namespace No operation. Use the or method to write the namespace declaration. ProcessingInstruction Writes out the processing instruction node. Comment Writes out the comment node. SignificantWhitespace Writes out the significant white space node. Whitespace Writes out the white space node. For the asynchronous version of this method, see . Copies everything from the object to the writer. The position of the remains unchanged. The to copy from. true to copy the default attributes; otherwise, false. Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously copies everything from the reader to the writer and moves the reader to the start of the next sibling. The task that represents the asynchronous WriteNode operation. The to read from. true to copy the default attributes from the XmlReader; otherwise, false. Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously copies everything from the object to the writer. The position of the remains unchanged. The task that represents the asynchronous WriteNode operation. The to copy from. true to copy the default attributes; otherwise, false. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The text would result in a non-well formed XML document. - or - is or . - or - This method is being used to create an XML declaration after has already been called. The is . The text to include in the processing instruction. This method can be used to write the XML declaration (rather than ). This could result in the encoding attribute being incorrectly written. For example, the following C# code would result in an invalid XML document because the default encoding is UTF-8. XmlWriter writer = XmlWriter.Create("output.xml"); writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-16'"); writer.WriteStartElement("root"); writer.Close(); If is either null or String.Empty, this method writes a ProcessingInstruction with no data content, for example <?name?>. If text contains an invalid sequence of "?>", the can either throw an ( objects) or insert a space "? >" to avoid writing invalid XML ( objects created by the method). For the asynchronous version of this method, see . When overridden in a derived class, writes out a processing instruction with a space between the name and text as follows: <?name text?>. The name of the processing instruction. The text to include in the processing instruction. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out a processing instruction with a space between the name and text as follows: <?name text?>. The task that represents the asynchronous WriteProcessingInstruction operation. The name of the processing instruction. The text to include in the processing instruction. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is , is , or is not a valid XML name. The is . is not a valid XML name. The namespace URI for the name. If maps to the current default namespace, no prefix is generated. When writing attribute values, this method generates a prefix if is not found. When writing element content, it throws an exception if is not found. If a class derived from the does not override this method is not checked to be a valid W3C XML name. In such case, before calling this method, the validity of the string can be checked by method. For the asynchronous version of this method, see . When overridden in a derived class, writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace. The local name to write. The namespace URI for the name. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace. The task that represents the asynchronous WriteQualifiedName operation. The local name to write. The namespace URI for the name. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . This method does not escape special characters. The does not validate the data that is passed to the method. You should not pass arbitrary data to this method. For the asynchronous version of this method, see . When overridden in a derived class, writes raw markup manually from a string. String containing the text to write. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is . The buffer length minus is less than . or is less than zero. The is . This method does not escape special characters. The does not validate the data that is passed to the method. You should not pass arbitrary data to this method. For the asynchronous version of this method, see . When overridden in a derived class, writes raw markup manually from a character buffer. Character array containing the text to write. The position within the buffer indicating the start of the text to write. The number of characters to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes raw markup manually from a string. The task that represents the asynchronous WriteRaw operation. String containing the text to write. Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes raw markup manually from a character buffer. The task that represents the asynchronous WriteRaw operation. Character array containing the text to write. The position within the buffer indicating the start of the text to write. The number of characters to write. Method 2.0.0.0 4.0.0.0 System.Void This method enables you to write a value using multiple Write methods. For the asynchronous version of this method, see . Writes the start of an attribute with the specified local name. The local name of the attribute. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . The namespace URI of the attribute. This is a more advanced version of that allows you to write an attribute value using multiple write methods, such as , , and so on. For the asynchronous version of this method, see . Writes the start of an attribute with the specified local name and namespace URI. The local name of the attribute. The namespace URI of the attribute. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is not one of the following: or . The local name of the attribute. The namespace URI for the attribute. This method enables you to write a value using multiple Write methods. For the asynchronous version of this method, see . When overridden in a derived class, writes the start of an attribute with the specified prefix, local name, and namespace URI. The namespace prefix of the attribute. The local name of the attribute. The namespace URI for the attribute. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the start of an attribute with the specified prefix, local name, and namespace URI. The task that represents the asynchronous WriteStartAttribute operation. The namespace prefix of the attribute. The local name of the attribute. The namespace URI for the attribute. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is not . The encoding level of the document is determined by how the writer is implemented. For example, if an object is specified in the XmlTextWriter constructor, this determines the value of the encoding attribute. This method does not create a standalone attribute. When WriteStartDocument is called the writer validates that what you are writing is a well-formed XML document. For example, it checks that the XML declaration is the first node, that one and only one root-level element exists, and so on. If this method is not called, the writer assumes an XML fragment is being written and applies no root level rules. If WriteStartDocument has been called and then the method is used to create another XML declaration, an exception will be thrown. For the asynchronous version of this method, see . When overridden in a derived class, writes the XML declaration with the version "1.0". 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is not . The encoding level of the document is determined by how the writer is implemented. For example, if an object is specified in the XmlTextWriter constructor, this determines the value of the encoding attribute. When WriteStartDocument is called, the writer validates that what you are writing is a well-formed XML document. For example, it checks that the XML declaration is the first node, that one and only one root-level element exists, and so on. If this method is not called, the writer assumes an XML fragment is being written and applies no root level rules. If WriteStartDocument has been called and then the method is used to create another XML declaration, an exception will be thrown. For the asynchronous version of this method, see . When overridden in a derived class, writes the XML declaration with the version "1.0" and the standalone attribute. If true, it writes "standalone=yes"; if false, it writes "standalone=no". 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the XML declaration with the version "1.0". The task that represents the asynchronous WriteStartDocument operation. Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the XML declaration with the version "1.0" and the standalone attribute. The task that represents the asynchronous WriteStartDocument operation. If true, it writes "standalone=yes"; if false, it writes "standalone=no". Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . For the asynchronous version of this method, see . When overridden in a derived class, writes out a start tag with the specified local name. The local name of the element. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . After calling this method you can either write attributes, or create content using , , or WriteStartElement for child elements. You can close the element with either or . For example, the following C# code: writer.WriteStartElement("item",null); writer.WriteString("some text"); writer.WriteEndElement(); Generates the following output: <item>some text</item> For the asynchronous version of this method, see . When overridden in a derived class, writes the specified start tag and associates it with the given namespace. The local name of the element. 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. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . See for an example demonstrating this method. For the asynchronous version of this method, see . When overridden in a derived class, writes the specified start tag and associates it with the given namespace and prefix. The namespace prefix of the element. The local name of the element. The namespace URI to associate with the element. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the specified start tag and associates it with the given namespace and prefix. The task that represents the asynchronous WriteStartElement operation. The namespace prefix of the element. The local name of the element. The namespace URI to associate with the element. Property 1.0.5000.0 2.0.0.0 4.0.0.0 System.Xml.WriteState One of the members of the enumeration. As described above. This property is read-only. This property must be overridden in order to provide the functionality as described herein, as there is no default implementation. Use this property to query the current state, for example, whether the writer is newly initialized, writing specific XML structures, or closed. When overridden in a derived class, gets the state of the writer. 0 Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void The is . WriteString does the following: The characters &, <, and > are replaced with &amp;, &lt;, and &gt;, respectively. The default behavior of an created using is to throw an when attempting to write character values in the range 0x-0x1F (excluding white space characters 0x9, 0xA, and 0xD). These invalid XML characters can be written by creating the with the property set to false. Doing so will result in the characters being replaced with numeric character entities (&#0; through &#0x1F). Additionally, an created with the new operator will replace the invalid characters with numeric character entities by default. Note   Microsoft does not encourage the practice of writing invalid XML characters since many applications that consume XML are not designed to handle invalid characters. If WriteString is called in the context of an attribute value, double and single quotes are replaced with &quot; and &apos; respectively. For example, this input string test<item>test is written out as test&lt;item&gt;test If is either null or String.Empty, this method writes a text node with no data content. For the asynchronous version of this method, see . When overridden in a derived class, writes the given text content. The text to write. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes the given text content. The task that represents the asynchronous WriteString operation. The text to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void An invalid surrogate character pair was passed. The is . The high surrogate. This must be a value between 0xD800 and 0xDBFF. This method is only applicable on systems that use UTF-16 encoding. The surrogate character entity is written in hexadecimal format. The range for surrogate characters is #x10000 to #x10FFFF. The following formula is used to generate the surrogate character entity: ( -0xD800) * 0x400 + ( -0xDC00) + 0x10000 For both HTML and XML, the document character set (and therefore the notation of numeric character references) is based on UCS [ISO-10646]. A single numeric character reference in a source document may therefore in some cases correspond to two 16-bit units in a string (a high surrogate and a low surrogate). These 16-bit units are referred to as a surrogate pair. For more information regarding surrogates or characters, refer to section 3.7 of the Unicode 3.0/Unicode 2.0 standard located at http://www.unicode.org, or section 2.2 of the W3C XML 1.0 Recommendation located at http://www.w3.org/TR/REC-xml#charsets. For the asynchronous version of this method, see . When overridden in a derived class, generates and writes the surrogate character entity for the surrogate character pair. The low surrogate. This must be a value between 0xDC00 and 0xDFFF. The high surrogate. This must be a value between 0xD800 and 0xDBFF. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously generates and writes the surrogate character entity for the surrogate character pair. The task that represents the asynchronous WriteSurrogateCharEntity operation. The low surrogate. This must be a value between 0xDC00 and 0xDFFF. The high surrogate. This must be a value between 0xD800 and 0xDBFF. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 4.0.0.0 System.Void For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a value. The value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime (CLR) object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. If the CLR object is a list type such as , , or , it is treated as an array of the value type. The converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes the object value. The object value to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. When the method is called, the converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the method. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, convert the return value of this method to a string and use the method. Writes a single-precision floating-point number. The single-precision floating-point number to write. Method 2.0.0.0 4.0.0.0 System.Void This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules. If is called multiple times in succession, the values are not delimited by a space. You must call between calls to to insert white space. Pass an array type to the overload to write out an array of distinct values. If this method is called on an instance that outputs text-only, the typed value is serialized to text. For asynchronous operations, use the method. Writes a value. The value to write. Method 1.0.5000.0 2.0.0.0 4.0.0.0 System.Void is or or contains non-white space characters. The is . This method is used to manually format your document. For the asynchronous version of this method, see . When overridden in a derived class, writes out the given white space. The string of white space characters. 0 Method 4.0.0.0 System.Threading.Tasks.Task This is the asynchronous version of , with the same functionality. To use this method, you must set the flag to true. Asynchronously writes out the given white space. The task that represents the asynchronous WriteWhitespace operation. The string of white space characters. Property 1.0.5000.0 2.0.0.0 4.0.0.0 System.String A containing the language attribute, or if the language attribute is not specified for the element. This property allows one component to find out in what state another component has left the writer. For example, perhaps one component wants to tell another which language help text to generate. The language information is communicated by writing an xml:lang attribute. When overridden in a derived class, gets the current xml:lang scope. 0 Property 1.0.5000.0 2.0.0.0 4.0.0.0 System.Xml.XmlSpace One of the members of the enumeration, or if the white space attribute is not specified for the element. This allows one component to find out what state another component has left the writer in. When overridden in a derived class, gets an representing the current xml:space scope. 0 0