System.Xml.XmlWriter Class

public abstract class XmlWriter

Base Types

Object
  XmlWriter

Assembly

System.Xml

Library

XML

Summary

Represents a writer that provides a non-cached, forward-only means of generating streams or files containing XML data.

Description

The output of this class conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

[Note: This class is abstract and is implemented in the XmlTextWriter class.

]

See Also

System.Xml Namespace

Members

XmlWriter Constructors

XmlWriter Constructor

XmlWriter Methods

XmlWriter.Close Method
XmlWriter.Flush Method
XmlWriter.LookupPrefix Method
XmlWriter.WriteAttributeString(System.String, System.String, System.String, System.String) Method
XmlWriter.WriteAttributeString(System.String, System.String) Method
XmlWriter.WriteAttributeString(System.String, System.String, System.String) Method
XmlWriter.WriteAttributes Method
XmlWriter.WriteBase64 Method
XmlWriter.WriteBinHex Method
XmlWriter.WriteCData Method
XmlWriter.WriteCharEntity Method
XmlWriter.WriteChars Method
XmlWriter.WriteComment Method
XmlWriter.WriteDocType Method
XmlWriter.WriteElementString(System.String, System.String, System.String) Method
XmlWriter.WriteElementString(System.String, System.String) Method
XmlWriter.WriteEndAttribute Method
XmlWriter.WriteEndDocument Method
XmlWriter.WriteEndElement Method
XmlWriter.WriteEntityRef Method
XmlWriter.WriteFullEndElement Method
XmlWriter.WriteName Method
XmlWriter.WriteNmToken Method
XmlWriter.WriteNode Method
XmlWriter.WriteProcessingInstruction Method
XmlWriter.WriteQualifiedName Method
XmlWriter.WriteRaw(char[], int, int) Method
XmlWriter.WriteRaw(System.String) Method
XmlWriter.WriteStartAttribute(System.String, System.String, System.String) Method
XmlWriter.WriteStartAttribute(System.String, System.String) Method
XmlWriter.WriteStartDocument(bool) Method
XmlWriter.WriteStartDocument() Method
XmlWriter.WriteStartElement(System.String) Method
XmlWriter.WriteStartElement(System.String, System.String) Method
XmlWriter.WriteStartElement(System.String, System.String, System.String) Method
XmlWriter.WriteString Method
XmlWriter.WriteSurrogateCharEntity Method
XmlWriter.WriteWhitespace Method

XmlWriter Properties

XmlWriter.WriteState Property
XmlWriter.XmlLang Property
XmlWriter.XmlSpace Property


XmlWriter Constructor

protected XmlWriter();

Summary

Constructs a new instance of the XmlWriter class.

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.Close Method

public abstract void Close();

Summary

Closes the writer.

Description

[Behaviors: This method closes any remaining open elements or attributes.

This method calls the System.Xml.XmlWriter.Flush method to flush the underlying buffered stream and then closes the stream.

This method sets the System.Xml.XmlWriter.WriteState to System.Xml.WriteState.Closed.

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.Flush Method

public abstract void Flush();

Summary

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

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.LookupPrefix Method

public abstract string LookupPrefix(string ns);

Summary

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

Parameters

ns
A String specifying the namespace URI.

Return Value

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

Exceptions

Exception TypeCondition
ArgumentExceptionns is null or System.String.Empty.

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteAttributeString(System.String, System.String, System.String, System.String) Method

public void WriteAttributeString(string prefix, string localName, string ns, string value);

Summary

Writes a new attribute with the specified prefix, local name, namespace URI, and value.

Parameters

prefix
A String specifying the namespace prefix of the attribute.
localName
A String specifying the local name of the attribute.
ns
A String specifying the namespace URI of the attribute.
value
A String specifying the value of the attribute.

Exceptions

Exception TypeCondition
ArgumentExceptionlocalName is null or System.String.Empty .
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.

Description

This method calls the following methods in order to write a complete attribute:

System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String)(prefix, localName, ns)

System.Xml.XmlWriter.WriteString(System.String)(value)

System.Xml.XmlWriter.WriteEndAttribute()

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteAttributeString(System.String, System.String) Method

public void WriteAttributeString(string localName, string value);

Summary

Writes a new attribute with the specified local name and value.

Parameters

localName
A String specifying the local name of the attribute.
value
A String specifying the value of the attribute.

Exceptions

Exception TypeCondition
ArgumentExceptionlocalName is null or System.String.Empty.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.

Description

This method calls the following methods in order to write a complete attribute:

System.Xml.XmlWriter.WriteStartAttribute(null , localName, null )

System.Xml.XmlWriter.WriteString(System.String)(value)

System.Xml.XmlWriter.WriteEndAttribute()

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteAttributeString(System.String, System.String, System.String) Method

public void WriteAttributeString(string localName, string ns, string value);

Summary

Writes a new attribute with the specified local name, namespace URI, and value.

Parameters

localName
A String specifying the local name of the attribute.
ns
A String specifying the namespace URI of the attribute.
value
A String specifying the value of the attribute.

Exceptions

Exception TypeCondition
ArgumentExceptionlocalName is null or System.String.Empty.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.

Description

This method calls the following methods in order to write a complete attribute:

System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String)(null , localName, ns)

System.Xml.XmlWriter.WriteString(System.String)(value)

System.Xml.XmlWriter.WriteEndAttribute()

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteAttributes Method

public virtual void WriteAttributes(XmlReader reader, bool defattr);

Summary

Writes the attributes found at the current position of a XmlReader.

Parameters

reader
A XmlReader from which to copy the attributes.
defattr
A Boolean where true specifies to copy the default attributes from reader; otherwise, false .

Exceptions

Exception TypeCondition
ArgumentNullExceptionreader is null .
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
XmlExceptionreader is not positioned on a node of XmlNodeTypeAttribute , Element , or XmlDeclaration .

Description

[Behaviors: If the reader is positioned on an Element or XmlDeclaration node, this method writes 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 closing tag is reached. If the reader is positioned on any other node type, this method throws an exception.]

[Default: This method positions the reader by calling its System.Xml.XmlReader.MoveToFirstAttribute and System.Xml.XmlReader.MoveToNextAttribute methods, and retrieves the value of the attributes by calling the System.Xml.XmlReader.ReadAttributeValue method of the reader.]

[Overrides: Override this method to remove any content that would invalidate the document. ]

[Usage: Use this method to write all the attributes found at the current position. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteBase64 Method

public abstract void WriteBase64(byte[] buffer, int index, int count);

Summary

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

Parameters

buffer
A Byte array containing the bytes to encode.
index
A Int32 specifying the position within the array of the first byte to encode.
count
A Int32 specifying the number of bytes to encode.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbuffer is null .
ArgumentExceptionThe buffer length minus index is less than count.
ArgumentOutOfRangeExceptionindex or count is less than zero.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Note: 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). ]

[Behaviors: As described above.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteBinHex Method

public abstract void WriteBinHex(byte[] buffer, int index, int count);

Summary

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

Parameters

buffer
A Byte array containing the bytes to encode.
index
A Int32 specifying the position within the array of the first byte to encode.
count
A Int32 specifying the number of bytes to encode.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbuffer is null .
ArgumentExceptionThe buffer length minus index is less than count.
ArgumentOutOfRangeExceptionindex or count is less than zero.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

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

[Behaviors: As described above.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteCData Method

public abstract void WriteCData(string text);

Summary

Writes out a CDATA block containing the specified text.

Parameters

text
A String specifying the text to place inside the CDATA block.

Exceptions

Exception TypeCondition
ArgumentExceptionThe text would result in a non-well formed XML document.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes <![CDATA[text]]>.

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

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteCharEntity Method

public abstract void WriteCharEntity(char ch);

Summary

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

Parameters

ch
The Char for which to generate the entity.

Exceptions

Exception TypeCondition
ArgumentExceptionThe character is in the surrogate pair character range, 0xd800 - 0xdfff, or the text would result in a non-well formed XML document.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method forces the generation of a character entity for the specified Unicode character value and writes the Unicode character in hexadecimal character entity reference format.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteChars Method

public abstract void WriteChars(char[] buffer, int index, int count);

Summary

Writes text a buffer at a time.

Parameters

buffer
A Char array containing the text to write.
index
A Int32 specifying the position within the array of the start of the text to write.
count
A Int32 specifying the number of characters to write.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbuffer is null .
ArgumentExceptionThe buffer length minus index is less than count.
ArgumentOutOfRangeExceptionindex or count is less than zero.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: As described above.]

[Overrides: When overriding this method, throw an exception 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 must be overridden in order to provide the functionality described above, as there is no default implementation.

]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteComment Method

public abstract void WriteComment(string text);

Summary

Writes a comment containing the specified text.

Parameters

text
A String containing the text to place inside the comment.

Exceptions

Exception TypeCondition
ArgumentExceptionThe text would result in a non-well formed XML document.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes <!--text-->.

If text is null or System.String.Empty, this method writes a comment with no content, <!---->.

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteDocType Method

public abstract void WriteDocType(string name, string pubid, string sysid, string subset);

Summary

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

Parameters

name
A String specifying the name of the document type.
pubid
A String specifying the public identifier, which is an alternative to the system identifier.

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

subset
A String specifying a URI that contains markup declarations.

Exceptions

Exception TypeCondition
ArgumentExceptionname is null or System.String.Empty.

-or-

The value for name would result in invalid XML.

InvalidOperationExceptionThis method was called outside the prolog (after the root element).

Description

[Behaviors: This method writes the document type declaration with the specified name and optional attributes. The optional attributes, pubid, sysid, and subset, are not checked for invalid characters.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteElementString(System.String, System.String, System.String) Method

public void WriteElementString(string localName, string ns, string value);

Summary

Writes an element with the specified local name, namespace URI, and value.

Parameters

localName
A String specifying the local name of the element.

ns
A String specifying the namespace URI to associate with the element.

value
A String specifying the value of the element.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

This method calls the following methods to write a complete element:

System.Xml.XmlWriter.WriteStartElement(System.String,System.String)(localName, ns)

System.Xml.XmlWriter.WriteString(System.String)(value) - this method is not called if value is either null or System.String.Empty

System.Xml.XmlWriter.WriteEndElement()

If any of the input parameters are null or System.String.Empty, the element is written with that parameter missing.

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteElementString(System.String, System.String) Method

public void WriteElementString(string localName, string value);

Summary

Writes an element with the specified local name and value.

Parameters

localName
A String specifying the local name of the element.

value
A String specifying the value of the element.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

This method is equivalent to System.Xml.XmlWriter.WriteElementString(System.String,System.String)(localName, null , value).

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteEndAttribute Method

public abstract void WriteEndAttribute();

Summary

Closes the attribute started with the System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String) method.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Attribute.

Description

[Behaviors: As described above.]

[Overrides: Override the System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String), System.Xml.XmlWriter.WriteAttributeString(System.String,System.String,System.String), and System.Xml.XmlWriter.WriteEndElement methods so these methods also close any attributes that are open when they are called. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteEndDocument Method

public abstract void WriteEndDocument();

Summary

Closes open elements and attributes and sets the System.Xml.XmlWriter.WriteState back to the System.Xml.WriteState.Start state.

Exceptions

Exception TypeCondition
ArgumentExceptionThe current instance is in the wrong WriteState, or the document does not have a root element.

Description

[Behaviors: This method closes all elements and attributes created by the System.Xml.XmlWriter.WriteStartElement(System.String,System.String) and System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String) methods, respectively, that are open when the System.Xml.XmlWriter.WriteEndDocument method is called. ]

[Overrides: This method must be overridden in order to provide the functionality as described herein, as there is no default implementation. ]

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

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteEndElement Method

public abstract void WriteEndElement();

Summary

Closes an open element and pops the corresponding namespace scope.

Exceptions

Exception TypeCondition
InvalidOperationExceptionNo element was open, or the System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method closes one 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.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteEntityRef Method

public abstract void WriteEntityRef(string name);

Summary

Writes an entity reference with the specified name.

Parameters

name
A String specifying the name of the entity reference.

Exceptions

Exception TypeCondition
ArgumentExceptionname is either null or System.String.Empty.

Description

[Behaviors: This method writes %name;.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteFullEndElement Method

public abstract void WriteFullEndElement();

Summary

Closes an open element and pops the corresponding namespace scope.

Exceptions

Exception TypeCondition
InvalidOperationExceptionNo element was open, or the System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method closes one element and pops the corresponding namespace scope. This method writes an end element regardless of whether there is any content in the element.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteName Method

public abstract void WriteName(string name);

Summary

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

Parameters

name
A String specifying the name to write.

Exceptions

Exception TypeCondition
ArgumentExceptionname is null or System.String.Empty; or name is not a valid XML Name.

InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteNmToken Method

public abstract void WriteNmToken(string name);

Summary

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

Parameters

name
A String specifying the name to write.

Exceptions

Exception TypeCondition
ArgumentExceptionname is null or System.String.Empty; or name is not a valid XML Nmtoken.

InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: As described above.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteNode Method

public virtual void WriteNode(XmlReader reader, bool defattr);

Summary

Writes the node found at the current position of the specified XmlReader, and all sub-nodes.

Parameters

reader
A XmlReader from which to copy the attributes.
defattr
A Boolean where true specifies to copy the default attributes from reader; otherwise, false .

Exceptions

Exception TypeCondition
ArgumentNullExceptionreader is null .
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: After the nodes are read, reader is moved to the next node at the same depth as the current node.]

[Default: If reader is in the System.Xml.ReadState.InitialSystem.Xml.XmlReader.ReadState, this method moves reader to the end of the stream. If reader is in the System.Xml.ReadState.EndOfFileSystem.Xml.XmlReader.ReadState, this method is non-operational. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlWriter class. ]

[Usage: Use this method to write the node found at the current position and all sub-nodes. ]

Example

The following example uses a XmlTextReader and a XmlTextWriter 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();
  }
}

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteProcessingInstruction Method

public abstract void WriteProcessingInstruction(string name, string text);

Summary

Writes a processing instruction with the specified name and text.

Parameters

name
A String specifying the name of the processing instruction.
text
A String specifying the text to include in the processing instruction.

Exceptions

Exception TypeCondition
ArgumentException The text would result in a non-well formed XML document.

- or -

name is null or System.String.Empty.

- or -

This method is being used to create an XML declaration after System.Xml.XmlWriter.WriteStartDocument has already been called.

InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes <?nametext?>.

If text is null or System.String.Empty, this method writes a processing instruction with no text content, <?name?>.

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteQualifiedName Method

public abstract void WriteQualifiedName(string localName, string ns);

Summary

Writes the qualified name.

Parameters

localName
A String specifying the local name to write.
ns
A String specifying the namespace URI to associate with localname.

Exceptions

Exception TypeCondition
ArgumentExceptionlocalName is null , is System.String.Empty, or is not a valid XML name.

InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes the qualified name. If ns maps to the current default namespace, no prefix is generated. When writing attribute values, this method generates a prefix if ns is not found. When writing element content, it throws an exception if ns is not found.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteRaw(char[], int, int) Method

public abstract void WriteRaw(char[] buffer, int index, int count);

Summary

Writes raw text from a character array.

Parameters

buffer
A Char array containing the text to write.
index
A Int32 specifying the position within the array of the start of the text to write.
count
A Int32 specifying the number of characters to write.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbuffer is null .
ArgumentExceptionThe buffer length minus index is less than count.
ArgumentOutOfRangeExceptionindex or count is less than zero.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes raw text from a character array. This method does not encode any characters.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteRaw(System.String) Method

public abstract void WriteRaw(string data);

Summary

Writes raw text from a string.

Parameters

data
A String specifying the text to write.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes raw text from a string. This method does not encode any characters. If data is null , System.String.Empty is written.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartAttribute(System.String, System.String, System.String) Method

public abstract void WriteStartAttribute(string prefix, string localName, string ns);

Summary

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

Parameters

prefix
A String specifying the namespace prefix of the attribute.
localName
A String specifying the local name of the attribute.
ns
A String specifying the namespace URI associated with the attribute.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not one of the following:System.Xml.WriteState.Attribute or System.Xml.WriteState.Element.

Description

[Behaviors: If any of the input parameters are null or System.String.Empty, the start attribute is written with that parameter missing.

]

[Overrides: When overriding this method, close any open attributes before writing the new attribute.

This method must be overridden in order to provide the functionality described above, as there is no default implementation.

]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartAttribute(System.String, System.String) Method

public void WriteStartAttribute(string localName, string ns);

Summary

Writes the start of an attribute.

Parameters

localName
A String specifying the local name of the attribute.
ns
A String specifying the namespace URI of the attribute.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

This method calls System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String)(null , localName, ns).

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartDocument(bool) Method

public abstract void WriteStartDocument(bool standalone);

Summary

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

Parameters

standalone
A Boolean where true indicates to write "standalone= yes"; false indicates to write "standalone=no".

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Start.

Description

[Note: Character encoding is set when the class in instantiated.

]

[Behaviors: As described above.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartDocument() Method

public abstract void WriteStartDocument();

Summary

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

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Start.

Description

[Note: Character encoding is set when the class in instantiated.

]

[Behaviors: As described above.]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartElement(System.String) Method

public void WriteStartElement(string localName);

Summary

Writes a start element with the specified name.

Parameters

localName
A String specifying the local name of the element.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

This method calls System.Xml.XmlWriter.WriteStartElement(System.String,System.String)(null , localName, null ).

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartElement(System.String, System.String) Method

public void WriteStartElement(string localName, string ns);

Summary

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

Parameters

localName
A String specifying the local name of the element.

ns
A String specifying the namespace URI to associate with the element.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

This method calls System.Xml.XmlWriter.WriteStartElement(System.String,System.String)(null , localName, ns).

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteStartElement(System.String, System.String, System.String) Method

public abstract void WriteStartElement(string prefix, string localName, string ns);

Summary

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

Parameters

prefix
A String specifying the namespace prefix of the element.
localName
A String specifying the local name of the element.

ns
A String specifying the namespace URI to associate with the element.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method writes a start element and name, and associates it with a namespace and prefix. If the namespace is already in scope and has an associated prefix, that prefix is automatically written also.

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

]

[Overrides: When overriding this method, also override the System.Xml.XmlWriter.WriteEndElement, System.Xml.XmlWriter.WriteString(System.String), and System.Xml.XmlWriter.WriteRaw(System.Char[],System.Int32,System.Int32) methods so they close any open start element. ]

[Usage: Use this method to write a specified start element and name, and associate it with a given namespace and prefix. Write any attributes using the System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String), System.Xml.XmlWriter.WriteString(System.String), and System.Xml.XmlWriter.WriteEndAttribute methods, then close the element using the System.Xml.XmlWriter.WriteEndElement method. ]

Example

See System.Xml.XmlTextWriter.WriteStartElement(System.String,System.String,System.String) for an example demonstrating this method.

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteString Method

public abstract void WriteString(string text);

Summary

Writes the specified text.

Parameters

text
A String specifying the text to write.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: This method performs the following conversions before writing the text:

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

]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteSurrogateCharEntity Method

public abstract void WriteSurrogateCharEntity(char lowChar, char highChar);

Summary

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

Parameters

lowChar
A Char containing the low surrogate. This must be a value between 0xDC00 and 0xDFFF.
highChar
A Char containing the high surrogate. This must be a value between 0xD800 and 0xDBFF.

Exceptions

Exception TypeCondition
ArgumentExceptionAn invalid surrogate character pair was passed.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Note: Applications encode DOM strings using UTF-16. 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 DOM 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.

]

[Behaviors: This method generates and writes the surrogate character entity for a surrogate character pair. 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: (highChar - 0xD800) * 0x400 + (lowChar - 0xDC00) + 0x10000. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteWhitespace Method

public abstract void WriteWhitespace(string ws);

Summary

Writes the given white space.

Parameters

ws
A String containing the white space characters.

Exceptions

Exception TypeCondition
ArgumentExceptionws is null or System.String.Empty or contains non-white space characters.
InvalidOperationExceptionThe System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.

Description

[Behaviors: As described above. ]

[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.WriteState Property

public abstract WriteState WriteState { get; }

Summary

Gets the write state of the writer.

Property Value

One of the members of the WriteState enumeration.

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality as described herein, as there is no default implementation. ]

[Usage: Use this property to query the current state, for example, whether the writer is newly initialized, writing specific XML structures, or closed. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.XmlLang Property

public abstract string XmlLang { get; }

Summary

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

Property Value

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

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace

XmlWriter.XmlSpace Property

public abstract XmlSpace XmlSpace { get; }

Summary

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

Property Value

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

Description

[Behaviors: As described above.

This property is read-only.

]

[Overrides: This property must be overridden in order to provide the functionality described above, as there is no default implementation. ]

See Also

System.Xml.XmlWriter Class, System.Xml Namespace