XmlWriter::WriteValue Method
Writes a single simple-typed value.
Assembly: System.Xml (in System.Xml.dll)
| Name | Description | |
|---|---|---|
![]() | WriteValue(Boolean) | Writes a Boolean value. |
![]() | WriteValue(DateTime) | Writes a DateTime value. |
![]() | WriteValue(DateTimeOffset) | Writes a DateTimeOffset value. |
![]() | WriteValue(Decimal) | Writes a Decimal value. |
![]() | WriteValue(Double) | Writes a Double value. |
![]() | WriteValue(Int32) | Writes a Int32 value. |
![]() | WriteValue(Int64) | Writes a Int64 value. |
![]() | WriteValue(Object^) | Writes the object value. |
![]() | WriteValue(Single) | Writes a single-precision floating-point number. |
![]() | WriteValue(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 |
|---|---|
xsd:boolean | |
xsd:integer | |
System::Byte array | xsd:base64Binary |
xsd:string | |
xsd:dateTime | |
xsd:decimal | |
xsd:double | |
xsd:integer | |
xsd:integer | |
xsd:integer | |
xsd:float | |
xsd:string | |
xsd:string | |
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.
