WriteValue Method
TOC
Collapse the table of content
Expand the table of content

XmlWriter.WriteValue Method

 

Writes a single simple-typed value.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

NameDescription
System_CAPS_pubmethodWriteValue(Boolean)

Writes a Boolean value.

System_CAPS_pubmethodWriteValue(DateTime)

Writes a DateTime value.

System_CAPS_pubmethodWriteValue(DateTimeOffset)

Writes a DateTimeOffset value.

System_CAPS_pubmethodWriteValue(Decimal)

Writes a Decimal value.

System_CAPS_pubmethodWriteValue(Double)

Writes a Double value.

System_CAPS_pubmethodWriteValue(Int32)

Writes a Int32 value.

System_CAPS_pubmethodWriteValue(Int64)

Writes a Int64 value.

System_CAPS_pubmethodWriteValue(Object)

Writes the object value.

System_CAPS_pubmethodWriteValue(Single)

Writes a single-precision floating-point number.

System_CAPS_pubmethodWriteValue(String)

Writes a String value.

Exception Condition
InvalidOperationException

An XmlWriter method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message “An asynchronous operation is already in progress.”

The WriteValue method accepts common language runtime (CLR) simple-typed values, converts them to their string representations according to the XML schema definition language (XSD) data type conversion rules, and writes them out by using the WriteString method. This enables you to pipeline simple-type values with minimal reparsing overhead when passing data between XPathDocument, XmlReader, and XmlWriter objects. This ability is also useful when dealing with CLR simple-types and an XmlWriter instance. You can call the WriteValue method to write the typed value instead of using the methods in the XmlConvert class to convert the typed data to a string value before writing it out.

For asynchronous operations, convert the return value of WriteValue to a string and use the WriteStringAsync method.

The following table shows the default XSD data types that correspond to CLR types.

If the CLR object is a list type, such as IEnumerable, IList, or ICollection, it is treated as an array of the value type.

CLR type

Default XSD data type

System.Boolean

xsd:boolean

System.Byte**

xsd:integer

System.Byte array

xsd:base64Binary

System.Char**

xsd:string

System.DateTime

xsd:dateTime

System.Decimal

xsd:decimal

System.Double

xsd:double

System.Int16**

xsd:integer

System.Int32

xsd:integer

System.Int64

xsd:integer

System.Single

xsd:float

System.String

xsd:string

System.IO.TextReader

xsd:string

System.IO.BinaryReader

xsd:base64Binary

**These types are not CLS-compliant. They do not have corresponding WriteValue methods.

If WriteValue is called multiple times in succession, the values are not delimited by a space. You must call WriteWhitespace between calls to WriteValue to insert white space.

Return to top
Show:
© 2016 Microsoft