public abstract class XmlWriter
Object
XmlWriter
System.Xml
XML
Represents a writer that provides a non-cached, forward-only means of generating streams or files containing XML data.
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.]
System.Xml Namespace
XmlWriter Constructors
XmlWriter Methods
XmlWriter.Close Method
XmlWriter.Flush Method
XmlWriter.LookupPrefix Method
XmlWriter.WriteAttributeString(System.String, System.String, System.String) Method
XmlWriter.WriteAttributeString(System.String, System.String) Method
XmlWriter.WriteAttributeString(System.String, 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) Method
XmlWriter.WriteElementString(System.String, 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(System.String) Method
XmlWriter.WriteRaw(char[], int, int) 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, System.String, System.String) Method
XmlWriter.WriteStartElement(System.String, System.String) Method
XmlWriter.WriteStartElement(System.String) Method
XmlWriter.WriteString Method
XmlWriter.WriteSurrogateCharEntity Method
XmlWriter.WriteWhitespace Method
XmlWriter Properties
XmlWriter.WriteState Property
XmlWriter.XmlLang Property
XmlWriter.XmlSpace Property
protected XmlWriter();
Constructs a new instance of the XmlWriter class.
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void Close();
Closes the writer.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void Flush();
Clears all buffers and causes any buffered data to be written to the underlying stream.
[Behaviors: As described above. ]
[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract string LookupPrefix(string ns);
Retrieves the prefix defined in the current namespace scope for the specified namespace URI.
- ns
- A String specifying the namespace URI.
A String containing the corresponding prefix, or System.String.Empty if the prefix is not found and ns is the default namespace, ornull
if no matching namespace URI is found in the current scope.
Exception Type Condition ArgumentException ns is null
or System.String.Empty.
[Behaviors: As described above. ]
[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteAttributeString(string localName, string ns, string value);
Writes a new attribute with the specified local name, namespace URI, and value.
- 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.
Exception Type Condition ArgumentException localName is null
or System.String.Empty.InvalidOperationException The System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.
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()
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteAttributeString(string localName, string value);
Writes a new attribute with the specified local name and value.
- localName
- A String specifying the local name of the attribute.
- value
- A String specifying the value of the attribute.
Exception Type Condition ArgumentException localName is null
or System.String.Empty.InvalidOperationException The System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.
This method calls the following methods in order to write a complete attribute:System.Xml.XmlWriter.XmlWriter.WriteStartAttribute(
null
, localName,null
)System.Xml.XmlWriter.WriteString(System.String)(value)
System.Xml.XmlWriter.WriteEndAttribute()
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteAttributeString(string prefix, string localName, string ns, string value);
Writes a new attribute with the specified prefix, local name, namespace URI, and value.
- 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.
Exception Type Condition ArgumentException localName is null
or System.String.Empty .InvalidOperationException The System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Element.
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()
System.Xml.XmlWriter Class, System.Xml Namespace
public virtual void WriteAttributes(XmlReader reader, bool defattr);
Writes the attributes found at the current position of a XmlReader.
- reader
- A XmlReader from which to copy the attributes.
- defattr
- A Boolean where
true
specifies to copy the default attributes from reader; otherwise,false
.
Exception Type Condition ArgumentNullException reader is null
.InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed. XmlException reader is not positioned on a node of XmlNodeType Attribute
,Element
, orXmlDeclaration
.
[Behaviors: If the reader is positioned on anElement
orXmlDeclaration
node, this method writes all the contained attributes. If the reader is positioned on anAttribute
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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteBase64(byte[] buffer, int index, int count);
Encodes the specified binary bytes as Base64 and writes out the resulting text.
- 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.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentException The buffer length minus index is less than count. ArgumentOutOfRangeException index or count is less than zero. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteBinHex(byte[] buffer, int index, int count);
Encodes the specified binary bytes as BinHex and writes the resulting text.
- 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.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentException The buffer length minus index is less than count. ArgumentOutOfRangeException index or count is less than zero. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteCData(string text);
Writes out a CDATA block containing the specified text.
- text
- A String specifying the text to place inside the CDATA block.
Exception Type Condition ArgumentException The text would result in a non-well formed XML document. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteCharEntity(char ch);
Forces the generation of a character entity for the specified Unicode character value.
- ch
- The Char for which to generate the entity.
Exception Type Condition ArgumentException The character is in the surrogate pair character range, 0xd800 - 0xdfff, or the text would result in a non-well formed XML document. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteChars(char[] buffer, int index, int count);
Writes text a buffer at a time.
- 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.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentException The buffer length minus index is less than count. ArgumentOutOfRangeException index or count is less than zero. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteComment(string text);
Writes a comment containing the specified text.
- text
- A String containing the text to place inside the comment.
Exception Type Condition ArgumentException The text would result in a non-well formed XML document. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteDocType(string name, string pubid, string sysid, string subset);
Writes the document type declaration with the specified name and optional attributes.
- 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.
Exception Type Condition ArgumentException name is null
or System.String.Empty.-or-
The value for name would result in invalid XML.
InvalidOperationException This method was called outside the prolog (after the root element).
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteElementString(string localName, string value);
Writes an element with the specified local name and value.
- localName
- A String specifying the local name of the element.
- value
- A String specifying the value of the element.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
This method is equivalent to System.Xml.XmlWriter.WriteElementString(System.String,System.String)(localName,null
, value).
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteElementString(string localName, string ns, string value);
Writes an element with the specified local name, namespace URI, and value.
- 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.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
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.EmptySystem.Xml.XmlWriter.WriteEndElement()
If any of the input parameters are
null
or System.String.Empty, the element is written with that parameter missing.
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteEndAttribute();
Closes the attribute started with the System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String) method.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteEndDocument();
Closes open elements and attributes and sets the System.Xml.XmlWriter.WriteState back to the System.Xml.WriteState.Start state.
Exception Type Condition ArgumentException The current instance is in the wrong WriteState, or the document does not have a root element.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteEndElement();
Closes an open element and pops the corresponding namespace scope.
Exception Type Condition InvalidOperationException No element was open, or the System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteEntityRef(string name);
Writes an entity reference with the specified name.
- name
- A String specifying the name of the entity reference.
Exception Type Condition ArgumentException name is either null
or System.String.Empty.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteFullEndElement();
Closes an open element and pops the corresponding namespace scope.
Exception Type Condition InvalidOperationException No element was open, or the System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteName(string name);
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).
- name
- A String specifying the name to write.
Exception Type Condition ArgumentException name is null
or System.String.Empty; or name is not a valid XML Name.
InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteNmToken(string name);
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).
- name
- A String specifying the name to write.
Exception Type Condition ArgumentException name is null
or System.String.Empty; or name is not a valid XML Nmtoken.
InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[Behaviors: As described above.]
[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public virtual void WriteNode(XmlReader reader, bool defattr);
Writes the node found at the current position of the specified XmlReader, and all sub-nodes.
- reader
- A XmlReader from which to copy the attributes.
- defattr
- A Boolean where
true
specifies to copy the default attributes from reader; otherwise,false
.
Exception Type Condition ArgumentNullException reader is null
.InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
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(); } }
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteProcessingInstruction(string name, string text);
Writes a processing instruction with the specified name and text.
- name
- A String specifying the name of the processing instruction.
- text
- A String specifying the text to include in the processing instruction.
Exception Type Condition 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.
InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteQualifiedName(string localName, string ns);
Writes the qualified name.
- localName
- A String specifying the local name to write.
- ns
- A String specifying the namespace URI to associate with localname.
Exception Type Condition ArgumentException localName is null
or System.String.Empty.
InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed. XmlException localName is not a valid XML name.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteRaw(string data);
Writes raw text from a string.
- data
- A String specifying the text to write.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[Behaviors: This method writes raw text from a string. This method does not encode any characters. If data isnull
, 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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteRaw(char[] buffer, int index, int count);
Writes raw text from a character array.
- 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.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentException The buffer length minus index is less than count. ArgumentOutOfRangeException index or count is less than zero. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteStartAttribute(string prefix, string localName, string ns);
Writes the start of an attribute with the specified prefix and name, and associates the prefix with the specified namespace URI.
- 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.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[Behaviors: If any of the input parameters arenull
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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteStartAttribute(string localName, string ns);
Writes the start of an attribute.
- localName
- A String specifying the local name of the attribute.
- ns
- A String specifying the namespace URI of the attribute.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
This method calls System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String)(null
, localName, ns).
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteStartDocument(bool standalone);
Writes the XML declaration with the version "1.0" and the standalone attribute.
- standalone
- A Boolean where
true
indicates to write "standalone= yes";false
indicates to write "standalone=no".
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Start.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteStartDocument();
Writes the XML declaration with the version "1.0" and no standalone attribute.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is not System.Xml.WriteState.Start.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteStartElement(string prefix, string localName, string ns);
Writes a start element with the specified name, and associates it with the given namespace and prefix.
- 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.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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. ]
See System.Xml.XmlTextWriter.WriteStartElement(System.String,System.String,System.String) for an example demonstrating this method.
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteStartElement(string localName, string ns);
Writes a start element with the specified name, and associates it with the given namespace.
- localName
- A String specifying the local name of the element.
- ns
- A String specifying the namespace URI to associate with the element.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
This method calls System.Xml.XmlWriter.WriteStartElement(System.String,System.String)(null
, localName, ns).
System.Xml.XmlWriter Class, System.Xml Namespace
public void WriteStartElement(string localName);
Writes a start element with the specified name.
- localName
- A String specifying the local name of the element.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
This method calls System.Xml.XmlWriter.WriteStartElement(System.String,System.String)(null
, localName,null
).
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteString(string text);
Writes the specified text.
- text
- A String specifying the text to write.
Exception Type Condition InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[Behaviors: This method performs the following conversions before writing the text:
If text is
- The characters '&', '<', and '>' are replaced with "&", "<", and ">", respectively.
- Character values in the range 0x-0x1F (excluding the white space characters 0x9, 0x10, and 0x13) are replaced with numeric character entities ("�" through "�x1F").
- If called in the context of an attribute value, double and single quotes are replaced with """ and "'" respectively.
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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteSurrogateCharEntity(char lowChar, char highChar);
Generates and writes the surrogate character entity for the surrogate character pair.
- 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.
Exception Type Condition ArgumentException An invalid surrogate character pair was passed. InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[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 may 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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract void WriteWhitespace(string ws);
Writes the given white space.
- ws
- A String containing the white space characters.
Exception Type Condition ArgumentException ws is null
or System.String.Empty or contains non-white space characters.InvalidOperationException The System.Xml.XmlWriter.WriteState is System.Xml.WriteState.Closed.
[Behaviors: As described above. ]
[Overrides: This method must be overridden in order to provide the functionality described above, as there is no default implementation. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract WriteState WriteState { get; }
Gets the write state of the writer.
One of the members of the WriteState enumeration.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract string XmlLang { get; }
Gets the language attribute,xml:lang
, specifying the language in which the content and attribute values of the current element are written.
A String containing the language attribute, ornull
if the language attribute is not specified for the element.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace
public abstract XmlSpace XmlSpace { get; }
Gets the white space attribute,xml:space
, specifying how white space is handled in the current element.
One of the members of the XmlSpace enumeration, or System.Xml.XmlSpace.None if the white space attribute is not specified for the element.
[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. ]
System.Xml.XmlWriter Class, System.Xml Namespace