Export (0) Print
Expand All

XmlWriter.WriteValue Method

Writes a single simple-typed value.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method WriteValue(Boolean) Writes a Boolean value.
Public method WriteValue(DateTime) Writes a DateTime value.
Public method WriteValue(DateTimeOffset) Writes a DateTimeOffset value.
Public method WriteValue(Decimal) Writes a Decimal value.
Public method WriteValue(Double) Writes a Double value.
Public method WriteValue(Int32) Writes a Int32 value.
Public method WriteValue(Int64) Writes a Int64 value.
Public method WriteValue(Object) Writes the object value.
Public method WriteValue(Single) Writes a single-precision floating-point number.
Public method WriteValue(String) Writes a String value.
Top

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.

Show:
© 2014 Microsoft