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.Xml.XmlWriter

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" />

This class implements the class.

In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

XmlTextWriter maintains a namespace stack corresponding to all the namespaces defined in the current element stack. Using XmlTextWriter you can declare namespaces manually.

`w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "x", null, "urn:1"); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteEndElement();`

The above C# code produces the following output. XmlTextWriter promotes the namespace declaration to the root element to avoid having it duplicated on the two child elements. The child elements pick up the prefix from the namespace declaration.

`<root xmlns:x="urn:1"> <x:item/> <x:item/> </x:root>`

XmlTextWriter also allows you to override the current namespace declaration. In the following example, the namespace URI "123" is overridden by "abc" to produce the XML element <x:node xmlns:x="abc"/>.

`w.WriteStartElement("x","node","123"); w.WriteAttributeString("xmlns","x",null,"abc");`

By using the write methods that take a prefix as an argument you can also specify which prefix to use. In the following example, two different prefixes are mapped to the same namespace URI to produce the XML text <x:root xmlns:x="urn:1"><y:item xmlns:y="urn:1"/></x:root>.

`XmlTextWriter w = new XmlTextWriter(Console.Out); w.WriteStartElement("x","root","urn:1"); w.WriteStartElement("y","item","urn:1"); w.WriteEndElement(); w.WriteEndElement(); w.Close();`

If there are multiple namespace declarations mapping different prefixes to the same namespace URI, XmlTextWriter walks the stack of namespace declarations backwards and picks the closest one.

`XmlTextWriter w = new XmlTextWriter(Console.Out); w.Formatting = Formatting.Indented; w.WriteStartElement("x","root","urn:1"); w.WriteStartElement("y","item","urn:1"); w.WriteAttributeString("attr","urn:1","123"); w.WriteEndElement(); w.WriteEndElement(); w.Close();`

In the above C# example, because the WriteAttributeString call does not specify a prefix, the writer uses the last prefix pushed onto the namespace stack, and produces the following XML:

`<x:root xmlns:x="urn:1"> <y:item y:attr="123" xmlns:y="urn:1" /> </x:root>`

If namespace conflicts occur, XmlTextWriter resolves them by generating alternate prefixes. For example, if an attribute and element have the same prefix but different namespaces, XmlWriter generates an alternate prefix for the attribute. The generated prefixes are named n{i} where i is a number beginning at 1. The number is reset to 1 for each element.

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 String is used as method parameter, null and String.Empty are equivalent. String.Empty follows the W3C rules.

To write strongly typed data, use the class to convert data types to string. For example, the following C# code converts the data from Double to String and writes the element <price>19.95</price>.

`Double price = 19.95; writer.WriteElementString("price", XmlConvert.ToString(price));`

XmlTextWriter does not check for the following:

Invalid characters in attribute and element names.

Unicode characters that do not fit the specified encoding. If the Unicode characters do not fit the specified encoding, the XmlTextWriter does not escape the Unicode characters into character entities.

Duplicate attributes.

Characters in the DOCTYPE public identifier or system identifier.

For more information about writing XML, see Writing XML with the XmlWriter.

## Security Considerations

The following items are things to consider when working with the class.

Exceptions thrown by the can disclose path information that you do not want bubbled up to the application. Your applications must catch exceptions and process them appropriately.

When you pass the to another application the underlying stream is exposed to that application. If you need to pass the to a semi-trusted application, you should use an object created by the method instead.

The does not validate any data that is passed to the or methods. You should not pass arbitrary data to these methods.

If the default settings are changed, there is no guarantee that the generated output is well-formed XML data.

Do not accept supporting components, such as an object, from an untrusted source.

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.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Creates an instance of the XmlTextWriter class using the specified .

  The TextWriter to write to. It is assumed that the TextWriter is already set to the correct encoding.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  cannot be written to.

  -or-

  The encoding is not supported.

  is .
  The encoding to generate. If encoding is null it writes out the stream as UTF-8 and omits the encoding attribute from the ProcessingInstruction.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Creates an instance of the XmlTextWriter class using the specified stream and encoding.

  The stream to which you want to write.
  The encoding to generate. If encoding is null it writes out the stream as UTF-8 and omits the encoding attribute from the ProcessingInstruction.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  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 .
  The encoding to generate. If encoding is null it writes the file out as UTF-8, and omits the encoding attribute from the ProcessingInstruction.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Creates an instance of the class using the specified file.

  The filename to write to. If the file exists, it truncates it and overwrites it with the new content.
  The encoding to generate. If encoding is null it writes the file out as UTF-8, and omits the encoding attribute from the ProcessingInstruction.
  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.Stream

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If the writer was constructed using a TextWriter that is derived from the StreamWriter class, this property is equivalent to the property. If the writer was constructed using a , this property returns the Stream passed to the constructor. If the writer was constructed using a file name, this property returns the Stream representing the file.

  Gets the underlying stream object.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Any elements or attributes left open are automatically closed.

  This method does not throw any exceptions.

  Closes this stream and the underlying stream.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This is called instead of when you want to write more to the underlying stream without losing what is still in the buffer.

  Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Xml.Formatting

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If the Indented option is set, child elements are indented using the and properties. Only element content is indented. The following C# code writes out HTML elements including mixed content:

  `XmlTextWriter w = new XmlTextWriter(Console.Out); w.Formatting = Formatting.Indented; w.WriteStartElement("ol"); w.WriteStartElement("li"); w.WriteString("The big "); // This means "li" now has a mixed content model. w.WriteElementString("b", "E"); w.WriteElementString("i", "lephant"); w.WriteString(" walks slowly."); w.WriteEndElement(); w.WriteEndElement();`

  The above code produces the following output:

  `<ol> <li>The big <b>E</b><i>lephant</i> walks slowly.</li> </ol>`

  When this is viewed in HTML no white space appears between the bold and italic elements. In fact, in this example, if indenting was added between these elements the word "Elephant" would be incorrectly broken.

  Writing any text content, excluding String.Empty puts that element into mixed content mode. Child elements do not inherit this "mixed" mode status. A child element of a "mixed" element does 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.

  Indicates how the output is formatted.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

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

  The value to be set is less than zero.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Indentation is performed on following node types: DocumentType, Element, Comment, ProcessingInstruction, and CDATASection. All other node types are not affected. The XmlTextWriter does not indent the internal DTD subset. However, you could do the following to apply formatting to the internal DTD subset.

  `String name = "Employees"; String pubid = null; String sysid = null; String subset = @" <!ELEMENT Employees (Employee)+> <!ELEMENT Employee EMPTY> <!ATTLIST Employee firstname CDATA #REQUIRED> <!ENTITY Company 'Microsoft'>]> "; XmlTextWriter tw = new XmlTextWriter(Console.Out); tw.WriteDocType(name, pubid, sysid, subset);`

  Gets or sets how many IndentChars to write for each level in the hierarchy when is set to Formatting.Indented.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Char

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Gets or sets which character to use for indenting when is set to Formatting.Indented.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` is or .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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.

  Namespace URI whose prefix you want to find. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

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

  The of the current instance is not .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This property determines whether the writer supports the W3C Namespaces in XML recommendation located at www.w3.org/TR/REC-xml-names.

  Gets or sets a value indicating whether to do namespace support.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Char

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

  The value to be set is not the single quote or double quote character.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Gets or sets which character to use to quote attribute values.

  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 .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Encodes the specified binary bytes as base64 and writes out the resulting text.

  Byte array to encode. The position within the buffer indicating the start of the bytes to write. The number of bytes 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 .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If is either null or String.Empty, this method writes an empty CDATA block, for example <![CDATA[]]>.

  Writes out a <![CDATA[...]]> block containing the specified text.

  Text to place inside the CDATA block. 0
- 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 .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

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

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

  Unicode character for which to generate a character entity. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` is .

  or is less than zero.

  - or -

  The buffer length minus is less than .

  The is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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.

  An exception is thrown if surrogate pair characters are written that would result in the surrogate pair characters being split in the buffer.

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If is either null or String.Empty, this method writes a Comment with no data content, for example <!---->.

  Writes out a comment <!--...--> containing the specified text.

  Text to place inside the comment. 0
- 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).

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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 any data that is passed to the method. You should not pass arbitrary data to this method.

  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
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void The is not.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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 .

  Closes the previous call.

  0
- 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. The current instance is in the wrong , or the document does not have a root element.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Closes any open elements or attributes and puts the writer back in the Start state.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void No element was open, or the is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If the element contains no content a short end tag "/>" is written; otherwise a full end tag is written.

  Closes one element and pops the corresponding namespace scope.

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Writes out an entity reference as &name;.

  Name of the entity reference. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void No start tag was open, or the is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

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

  Closes one element and pops the corresponding namespace scope.

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

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If is set to true, WriteName also checks that the name is also valid according to the W3C Namespaces in XML recommendation.

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

  Name to write. 0
- 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 .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

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

  Name to write. 0
- 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 . Text to include in the processing instruction.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  If is either null or String.Empty, this method writes a ProcessingInstruction with no data content, for example <?name?>.

  Writes out a processing instruction with a space between the name and text as follows: <?name text?>.

  Name of the processing instruction. Text to include in the processing instruction. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  is or .

  -or-

  is , and is neither nor .

  -or-

  is not a valid XML name.

  The is . is not a valid XML name. The namespace URI to associate with the name.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  For example, the following Microsoft Visual C# code:

  `writer.Formatting = Formatting.Indented; writer.WriteStartElement("root"); writer.WriteAttributeString("xmlns","x",null,"urn:abc"); writer.WriteStartElement("item"); writer.WriteStartAttribute("href",null); writer.WriteString("#"); writer.WriteQualifiedName("test","urn:abc"); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteEndElement(); writer.Close();`

  Generates the following output:

  `<root xmlns:x="urn:abc"> <item href="#x:test"/> </root>`

  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 this writer supports namespaces ( is set to true), this method also checks that the name is valid according to the W3C Namespaces in XML recommendation (http://www.w3.org/TR/REC-xml-names).

  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 to associate with the name. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` The is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This method does not escape special characters.

  The does not validate any data that is passed to the method. You should not pass arbitrary data to this method.

  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 .

  or is less than zero.

  - or -

  The buffer length minus is less than .

  The is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This method does not escape special characters.

  The does not validate any data that is passed to the method. You should not pass arbitrary data to this method.

  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
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` is for the writer, and and are not both or . The is not one of the following: or . Namespace prefix of the attribute.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This is a more advanced version of that allows you to write an attribute value using multiple write methods, such as .

  Writes the start of an attribute.

  Namespace prefix of the attribute. LocalName of the attribute. NamespaceURI of the attribute 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void The is not .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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 is thrown.

  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 .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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 is thrown.

  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
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` 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.

  The namespace prefix of the element.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  After calling this method you can either write attributes or create content using , , or for child elements. You can close the element with at which time an end tag is written out.

  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. If this namespace is already in scope and has an associated prefix then the writer automatically writes that prefix also. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Xml.WriteState

  One of the members of the enumeration.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  Gets the state of the writer.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` 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;

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  WriteString does the following

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

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

  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 as

  `test&lt;item&gt;test`

  If is either null or String.Empty, this method writes a text node with no data content.

  Writes the given text content.

  Text to write. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` An invalid surrogate character pair was passed. The is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  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.

  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
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is or or contains non-white space characters. The is .

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This method is used to manually format your document. Use the property to have the writer format the output automatically.

  Writes out the given white space.

  The string of white space characters. 0
- 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.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This property allows one component to find out what state another component has left the writer in. 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.

  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.

  In the dnprdnext release, the recommended practice is to create instances using the method and the class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

  This property allows one component to find out in what state another component has left the writer.

  Gets an representing the current xml:space scope.

  0
0