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 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Xml.XmlWriter

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.

This class maintains a namespace stack corresponding to all the namespaces defined in the current element stack. Namespaces can be declared manually to override the current namespace declaration. Prefixes can be specified to associate with a namespace. If there are multiple namespace declarations mapping different prefixes to the same namespace URI, this class walks the stack of namespace declarations backwards and picks the closest one.

If namespace conflicts occur inside an element, this class resolves the conflict by generating alternate prefixes. The generated prefixes are named ni, where n is the literal character 'n' and i is a number beginning at one. The number is reset to one for each element. See the example section for a demonstration of this behavior.

Attributes which are associated with a namespace URI must have a prefix (default namespaces do not apply to attributes). This conforms to section 5.2 of the W3C Namespaces in XML recommendation. If an attribute references a namespace URI, but does not specify a prefix, the writer generates a prefix for the attribute.

When writing an empty element, an additional space is added between tag name and the closing tag, for example <item />. This provides compatibility with older browsers.

When a is used as method parameter, and are equivalent. follows the W3C rules.

This class implements the class.

The following example demonstrates how this class resolves namespace conflicts inside an element. In the example, the writer writes an element that contains two attributes. The element and both attributes have the same prefix but different namespaces. The resulting XML fragment is written to the console.

`using System; using System.Xml; public class WriteFragment { public static void Main() { XmlTextWriter xWriter = new XmlTextWriter(Console.Out); xWriter.WriteStartElement("prefix", "Element1", "namespace"); xWriter.WriteStartAttribute("prefix", "Attr1", "namespace1"); xWriter.WriteString("value1"); xWriter.WriteStartAttribute("prefix", "Attr2", "namespace2"); xWriter.WriteString("value2"); xWriter.Close(); } }`

The output is

<prefix:Element1 n1:Attr1="value1" n2:Attr2="value2" xmlns:n2="namespace2" xmlns:n1="namespace1" xnlns:prefix="namespace" />

- Constructor
  The to write to, initialized to the correct encoding.

  Constructs and initializes a new instance of the class.

  The following properties are initialized to the specified values:

  to .

  to 2.

  to the space character.

  to .

  to the double quote character.

  to .

  If a specific encoding is necessary, set the encoding using the constructor of before instantiating the writer.

  0
  1.0.5000.0
  2.0.0.0
- Constructor
  To be added.
  The to generate, or .
  To be added.

  Constructs and initializes a new instance of the class using the specified output stream.

  If is , the stream is written as UTF-8 and the encoding attribute is omitted from the processing instruction.

  The following properties are initialized to the specified values:

  to .

  to 2.

  to the space character.

  to .

  to the double quote character.

  to .

  cannot be written to.

  -or-

  The encoding is not supported.

  is .
  0
  1.0.5000.0
  2.0.0.0
- Constructor
  A specifying the path and name of the file to write to.
  The to generate, or .
  To be added.

  Constructs and initializes a new instance of the class using the specified file.

  If exists, it is truncated and overwritten with the new content.

  If is , the file is written as UTF-8 and the encoding attribute is omitted from the processing instruction.

  The following properties are initialized to the specified values:

  to .

  to 2.

  to the space character.

  to .

  to the double quote character.

  to .

  is , contains only white space, or contains one or more implementation-specific invalid characters.

  -or-

  The encoding is not supported.

  is .
  The directory path specified in does not exist.
  includes an invalid syntax for the path or file name.
  The specified path, file name, or both exceeds the system-defined maximum length.
  The caller does not have the required permissions.
  Write access is not permitted by the operating system for the path specified in .
  Requires permission to write to files. See .
  0
  1.0.5000.0
  2.0.0.0
- Property
  System.IO.Stream

  Gets the underlying stream used by the writer.

  A , or if the current instance does not use an underlying stream.

  This property is read-only.

  If the current instance was constructed using a that is a subclass of the class, this property is equivalent to the

  property.

  If the writer was constructed using a , this property returns the passed to the constructor.

  If the writer was constructed using a file name, this property returns the representing the file.

  0
  1.0.5000.0
  2.0.0.0
- Method
  System.Void

  Closes the writer.

  This method closes all elements and attributes created by the and methods, respectively, that are open when the method is called.

  This method calls the method to flush the underlying buffered stream and then closes the stream.

  This method sets the to .

  0
  1.0.5000.0
  2.0.0.0
- Method
  System.Void

  Clears all buffers and causes any buffered data to be written to the underlying stream.

  This method overrides .

  0
  1.0.5000.0
  2.0.0.0
- Property
  System.Xml.Formatting

  Indicates how the output is formatted.

  One of the members of the enumeration. The default is (no special formatting).

  If this property is set to , child elements are indented using the and

  properties. Only element content will be indented.

  Writing any text content, including , puts that element into mixed content mode. Child elements do not inherit this "mixed" mode status. A child element of a "mixed" element will do indenting, unless it is also contains "mixed" content. Element content (http://www.w3.org/TR/1998/REC-xml-19980210#sec-element-content) and mixed content (http://www.w3.org/TR/1998/REC-xml-19980210#sec-mixed-content) are defined according to the XML 1.0 definitions of these terms.

  0
  1.0.5000.0
  2.0.0.0
- Property
  System.Int32

  Gets or sets how many indentation characters to write for each level in the hierarchy when is set to .

  A specifying the number of characters to use for each level. The default is 2.

  Indentation is performed on the following members of : , , , , and . All other node types are not affected. The class does not indent the internal DTD subset.

  The value to be set is less than zero. 0 1.0.5000.0 2.0.0.0
- Property
  System.Char

  Gets or sets the character to use for indenting when is set to .

  A specifying the character to use for indenting. The default is space (character code 0x20).

  This property can be set to any character. To ensure valid XML, set this property to a valid white space character: 0x9, 0x10, 0x13, or 0x20.

  0
  1.0.5000.0
  2.0.0.0
- Method
  System.String `` A specifying the namespace URI.

  Returns the prefix defined in the current namespace scope for the specified namespace URI.

  A containing the corresponding prefix, or if the prefix is not found and is the default namespace, or if no matching namespace URI is found in the current scope.

  This method overrides .

  is or . 0 1.0.5000.0 2.0.0.0
- Property
  System.Boolean

  Gets or sets a value indicating whether the writer supports namespaces.

  A where indicates the writer supports namespaces; otherwise, . The default is .

  This property determines whether the writer supports the XML Namespaces specification (http://www.w3.org/TR/REC-xml-names).

  If an attempt is made to set this property after a write operation has occurred, a is thrown.

  The of the current instance is not . 0 1.0.5000.0 2.0.0.0
- Property
  System.Char

  Gets or sets the character used to quote the value of an attribute.

  A specifying the quotation mark character (" or ') used to enclose the value of an attribute. The default is the double quote.

  To be added. The value to be set is not the single quote or double quote character. 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A array containing the bytes to encode. A specifying the position within the array of the first byte to encode. A specifying the number of bytes to encode.

  Encodes the specified binary bytes as Base64 and writes the resulting text.

  Base64 encoding represents byte sequences in a text form comprised of the 65 US-ASCII characters (A-Z, a-z, 0-9, +, /, =) where each character encodes 6 bits of the binary data.

  For more information on Base64 encoding, see RFC 2045 (http://www.ietf.org/rfc/rfc2045).

  This method overrides .

  is . The buffer length minus is less than . or is less than zero. The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A array containing the bytes to encode. A specifying the position within the array of the first byte to encode. A specifying the number of bytes to encode.

  Encodes the specified binary bytes as BinHex and writes the resulting text.

  For information on BinHex encoding, see RFC 1741 (http://www.ietf.org/rfc/rfc1741).

  This method overrides .

  is . The buffer length minus is less than . or is less than zero. The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A specifying the text to place inside the CDATA block.

  Writes out a CDATA block containing the specified text.

  This method writes <![CDATA[]]>.

  If is or , this method writes an empty CDATA block, <![CDATA[]]>.

  This method overrides .

  The text would result in a non-well formed XML document. The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` The for which to generate the entity.

  Forces the generation of a character entity for the specified Unicode character value.

  This method writes the Unicode character in hexadecimal character entity reference format.

  This method overrides .

  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 . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A array containing the text to write. A specifying the position within the array of the start of the text to write. A specifying the number of characters to write.

  Writes text a buffer at a time.

  This method can be used to write large amounts of text a buffer at a time.

  An exception is thrown if surrogate pair characters would be split across multiple buffer writes. This exception must be caught in order to continue writing the next surrogate pair characters. The XML specification defines the valid ranges for surrogate pairs.

  This method overrides .

  is .

  or is less than zero.

  - or -

  The buffer length minus is less than .

  The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A containing the text to place inside the comment.

  Writes out a comment containing the specified text.

  This method writes <!---->.

  If is or , this method writes a comment with no content, <!---->.

  This method overrides .

  The text would result in a non-well formed XML document The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` `` A specifying the name of the document type.

  A specifying the public identifier, which is an alternative to the system identifier.

  A specifying the system identifier, which is the URI of the DTD (document type definition) for the document.

  A specifying a URI that contains markup declarations.

  Writes the document type declaration with the specified name and optional attributes.

  The optional attributes, , , and , are not checked for invalid characters.

  A document type declaration is of the following form:

  <!DOCTYPE PUBLIC "" "" []>

  This method overrides .

  is or .

  -or-

  The value for would result in invalid XML.

  This method was called outside the prolog (after the root element). 0 1.0.5000.0 2.0.0.0
- Method
  System.Void

  Closes the attribute started with the method.

  The and methods also will close an open attribute if one exists when they are called.

  This method overrides .

  The is not. 0 1.0.5000.0 2.0.0.0
- Method
  System.Void

  Closes open elements and attributes and sets the back to the state.

  This method closes all elements and attributes created by the and methods, respectively, that are open when the method is called.

  After calling this method, the current instance can be used to write a new XML document.

  This method overrides .

  The current instance is in the wrong , or the document does not have a root element. The current instance is in the wrong , or the document does not have a root element. 0 1.0.5000.0 2.0.0.0
- Method
  System.Void

  Closes an open element and pops the corresponding namespace scope.

  If the open element does not contain content, it is closed as an empty element using " />"; otherwise an end element is written.

  This method overrides .

  No element was open, or the is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A specifying the name of the entity reference.

  Writes an entity reference with the specified name.

  This method writes %;.

  This method overrides .

  A containing the text would result in a non-well formed XML document, or is either or . The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void

  Closes an open element and pops the corresponding namespace scope.

  This method writes an end element regardless of whether there is any content in the element.

  This method overrides .

  No start tag was open, or the is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A specifying the name to write.

  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).

  If is set to , this method checks that is also valid according to the W3C Namespaces in XML recommendation (http://www.w3.org/TR/REC-xml-names).

  This method overrides .

  is or ; or is not a valid XML Name.

  The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A specifying the name to write.

  Writes out the specified name, ensuring it is a valid name token (Nmtoken) according to the W3C XML 1.0 recommendation (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

  This method overrides .

  is or ; or is not a valid XML Nmtoken.

  The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` A specifying the name of the processing instruction. A specifying the text to include in the processing instruction. To be added.

  Writes out a processing instruction with the specified name and text.

  This method writes <??>.

  If is or , this method writes a processing instruction with no text content, <??>.

  This method overrides .

  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 . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` A specifying the local name to write. A specifying the namespace URI to associate with . To be added.

  Writes out the qualified 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, this method throws an exception if is not found.

  If the current instance supports namespaces ( is set to ), this method looks up the prefix that is in scope for the given namespace and checks that the name is valid according to the W3C Namespaces in XML recommendation (http://www.w3.org/TR/REC-xml-names).

  This method overrides .

  is or .

  -or-

  is , and is neither nor .

  -or-

  is not a valid XML name.

  The is . is not a valid XML name. 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A specifying the text to write.

  Writes raw text from a string.

  If is , is written.

  This method does not encode any characters.

  This method overrides .

  The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A array containing the text to write. A specifying the position within the array of the start of the text to write. A specifying the number of characters to write.

  Writes raw text from a character array.

  This method does not encode any characters.

  This method overrides .

  is .

  or is less than zero.

  - or -

  The buffer length minus is less than .

  The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A specifying the namespace prefix of the attribute. A specifying the local name of the attribute. To be added. To be added.

  Writes the start of an attribute with the specified prefix and name, and associates the prefix with the specified namespace URI.

  If any of the input parameters are or , the start attribute is written with that parameter missing.

  This method overrides .

  is for the writer, and and are not both or . The is not one of the following: or . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void

  Writes the XML declaration with the version "1.0" and no standalone attribute.

  When is instantiated, the is set to . All the "write" methods change the to a value other than . Thus, if this method is not the first "write" method called, a

  is thrown.

  If has been called and then the method is used to create another XML declaration, a will be thrown.

  The output of this method using an encoding equal to and the default is

  <?xml version="1.0" encoding="utf-16"?>

  Character encoding is set when the writer is instantiated.

  This method overrides .

  The is not . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A where indicates to write "yes" as the value for the standalone attribute, and indicates to write "no".

  Writes the XML declaration with the version "1.0" and the standalone attribute.

  When is instantiated, the is set to . All the "write" methods change the to a value other than . Thus, if this method is not the first "write" method called, a

  is thrown.

  If has been called and then the method is used to create another XML declaration, a will be thrown.

  The output of this method with equal to , an encoding equal to , and using the default is:

  <?xml version="1.0" encoding="utf-16" standalone="yes"?>

  Character encoding is set when the writer is instantiated.

  This method overrides .

  The is not . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` `` `` A specifying the namespace prefix of the element.

  A specifying the local name of the element.

  To be added. To be added.

  Writes a start element with the specified name, and associates it with the given namespace and prefix.

  If is already in scope and has an associated prefix, the current instance will automatically write that prefix also.

  If any of the input parameters are or , the start element is written with that parameter missing.

  Write any attributes using the , , and methods, then close the element using the method.

  This method overrides .

  is for the writer, and and are not both . The is .

  This example demonstrates the method, writing the XML to the console.

  `using System; using System.Xml; public class WriteXml { public static void Main() { XmlTextWriter xWriter = new XmlTextWriter(Console.Out); xWriter.WriteStartDocument(); xWriter.WriteStartElement("prefix","element", "namespace"); xWriter.WriteEndDocument(); } }`

  The output is

  <?xml version="1.0" encoding= "someencoding"?>

  <prefix:element xmlns:prefix="namespace" />

  The value of the encoding attribute is the encoding of the output stream of the console.

  0
  1.0.5000.0
  2.0.0.0
- Property
  System.Xml.WriteState

  Gets the write state of the writer.

  One of the members of the enumeration.

  This property is read-only.

  This property overrides .

  0
  1.0.5000.0
  2.0.0.0
- Method
  System.Void `` A specifying the text to write.

  Writes the specified text.

  This method performs the following conversions before writing the text:

  The characters '&', '<', and '>' are replaced with "&amp;", "&lt;", and "&gt;", respectively.

  Character values in the range 0x-0x1F (excluding the white space characters 0x9, 0x10, and 0x13) are replaced with numeric character entities ("&#0;" through "&#0x1F").

  If called in the context of an attribute value, double and single quotes are replaced with "&quot;" and "&apos;" respectively.

  If is or , this method writes a text node with no data content.

  This method overrides .

  The is and is neither nor .

  The following example demonstrates the conversions performed by this method.

  `using System; using System.Xml; public class WriteFrag { public static void Main() { XmlTextWriter xtWriter = new XmlTextWriter(Console.Out); xtWriter.WriteString("<1 & 2 = 3>"); } }`

  The output is

  &lt;1 &amp; 2 = 3&gt;

  0
  1.0.5000.0
  2.0.0.0
- Method
  System.Void `` `` To be added. To be added.

  Generates and writes the surrogate character entity for the surrogate character pair.

  This method only applies to a writer that uses the UTF-16 encoding type.

  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 might 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 .

  This method overrides .

  An invalid surrogate character pair was passed. The is . 0 1.0.5000.0 2.0.0.0
- Method
  System.Void `` A containing the white space characters.

  Writes the given white space.

  This method is used to manually format a document. Use the property to have the current instance format the output automatically.

  This method overrides .

  is or or contains non-white space characters. The is . 0 1.0.5000.0 2.0.0.0
- Property
  System.String

  Gets the language attribute, xml:lang, specifying the language in which the content and attribute values of the current element are written.

  A containing the language attribute, or if the language attribute is not specified for the element.

  This property is read-only.

  This property overrides .

  0
  1.0.5000.0
  2.0.0.0
- Property
  System.Xml.XmlSpace

  Gets the white space attribute, xml:space, specifying how white space is handled in the current element.

  One of the members of the enumeration, or if the white space attribute is not specified for the element.

  This property is read-only.

  This property overrides .

  0
  1.0.5000.0
  2.0.0.0
0