XmlWriter.WriteValue 方法

定義

寫入單一簡單類型的值。Writes a single simple-typed value.

多載

WriteValue(Single)

寫入單精確度浮點數。Writes a single-precision floating-point number.

WriteValue(Object)

寫入物件值。Writes the object value.

WriteValue(Int64)

寫入 Int64 值。Writes a Int64 value.

WriteValue(Int32)

寫入 Int32 值。Writes a Int32 value.

WriteValue(Double)

寫入 Double 值。Writes a Double value.

WriteValue(String)

寫入 String 值。Writes a String value.

WriteValue(DateTimeOffset)

寫入 DateTimeOffset 值。Writes a DateTimeOffset value.

WriteValue(DateTime)

寫入 DateTime 值。Writes a DateTime value.

WriteValue(Boolean)

寫入 Boolean 值。Writes a Boolean value.

WriteValue(Decimal)

寫入 Decimal 值。Writes a Decimal value.

備註

WriteValue方法會接受 common language runtime (CLR) 簡單類型的值,根據 XML 架構定義語言 (XSD) 資料類型轉換規則,將它們轉換成其字串表示,然後使用方法將它們寫出 WriteStringThe 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. 這可讓您在 XPathDocument 、和物件之間傳遞資料時,以基本的重新剖析額外負荷來管線處理簡單類型的值 XmlReader XmlWriterThis enables you to pipeline simple-type values with minimal reparsing overhead when passing data between XPathDocument, XmlReader, and XmlWriter objects. 這項功能在處理 CLR 簡單類型和實例時也很有用 XmlWriterThis ability is also useful when dealing with CLR simple-types and an XmlWriter instance. 您可以呼叫 WriteValue 方法來寫入具類型的值,而不是使用類別中的方法,將具 XmlConvert 類型的資料轉換成字串值,然後再將其寫出。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.

若為非同步作業,請將的傳回值轉換 WriteValue 為字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of WriteValue to a string and use the WriteStringAsync method.

下表顯示對應至 CLR 類型的預設 XSD 資料類型。The following table shows the default XSD data types that correspond to CLR types.

如果 CLR 物件是清單型別 (如 IEnumerableIListICollection),則會將其視為數值型別的陣列。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 類型CLR type 預設 XSD 資料類型Default XSD data type
System.Boolean xsd:booleanxsd:boolean
System.Byte** xsd:integerxsd:integer
System.Byte 陣列System.Byte array xsd:base64Binaryxsd:base64Binary
System.Char** xsd:stringxsd:string
System.DateTime xsd:dateTimexsd:dateTime
System.Decimal xsd:decimalxsd:decimal
System.Double xsd:doublexsd:double
System.Int16** xsd:integerxsd:integer
System.Int32 xsd:integerxsd:integer
System.Int64 xsd:integerxsd:integer
System.Single xsd:floatxsd:float
System.String xsd:stringxsd:string
System.IO.TextReader xsd:stringxsd:string
System.IO.BinaryReader xsd:base64Binaryxsd:base64Binary

**這些型別與 CLS 不相容。**These types are not CLS-compliant. 它們沒有對應的 WriteValue 方法。They do not have corresponding WriteValue methods.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space.

WriteValue(Single)

寫入單精確度浮點數。Writes a single-precision floating-point number.

public:
 virtual void WriteValue(float value);
public virtual void WriteValue (float value);
abstract member WriteValue : single -> unit
override this.WriteValue : single -> unit
Public Overridable Sub WriteValue (value As Single)

參數

value
Single

要寫入的單精確度浮點數。The single-precision floating-point number to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Object)

寫入物件值。Writes the object value.

public:
 virtual void WriteValue(System::Object ^ value);
public virtual void WriteValue (object value);
abstract member WriteValue : obj -> unit
override this.WriteValue : obj -> unit
Public Overridable Sub WriteValue (value As Object)

參數

value
Object

要寫入的物件值。The object value to write.

附註:使用 .NET Framework 3.5 的版本時,這個方法會接受 DateTimeOffset 作為參數。Note With the release of the .NET Framework 3.5, this method accepts DateTimeOffset as a parameter.

例外狀況

指定了無效的值。An invalid value was specified.

valuenullThe value is null.

寫入器的狀態為關閉或錯誤。The writer is closed or in error state.

-或--or-

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會使用 common language runtime (CLR) 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime (CLR) object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

如果 CLR 物件是清單類型 IEnumerable ,例如、 IListICollection ,則會將它視為實值型別的陣列。If the CLR object is a list type such as IEnumerable, IList, or ICollection, it is treated as an array of the value type. XmlWriter會根據 XML 架構 (XSD) 資料類型規則,將值轉換成其字串表示,並使用方法將其寫出 WriteStringThe XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Int64)

寫入 Int64 值。Writes a Int64 value.

public:
 virtual void WriteValue(long value);
public virtual void WriteValue (long value);
abstract member WriteValue : int64 -> unit
override this.WriteValue : int64 -> unit
Public Overridable Sub WriteValue (value As Long)

參數

value
Int64

要寫入的 Int64 值。The Int64 value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Int32)

寫入 Int32 值。Writes a Int32 value.

public:
 virtual void WriteValue(int value);
public virtual void WriteValue (int value);
abstract member WriteValue : int -> unit
override this.WriteValue : int -> unit
Public Overridable Sub WriteValue (value As Integer)

參數

value
Int32

要寫入的 Int32 值。The Int32 value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Double)

寫入 Double 值。Writes a Double value.

public:
 virtual void WriteValue(double value);
public virtual void WriteValue (double value);
abstract member WriteValue : double -> unit
override this.WriteValue : double -> unit
Public Overridable Sub WriteValue (value As Double)

參數

value
Double

要寫入的 Double 值。The Double value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

範例

下列範例會使用具類型的資料來寫入書籍節點。The following example writes a book node using typed data.

Double price = 9.95;
DateTime date = new DateTime(2004, 5, 20);

using (XmlWriter writer = XmlWriter.Create("data.xml"))
{
    writer.WriteStartElement("book");
    writer.WriteStartAttribute("pub-date");
    writer.WriteValue(date);
    writer.WriteEndAttribute();

    writer.WriteStartElement("price");
    writer.WriteValue(price);
    writer.WriteEndElement();

    writer.WriteEndElement();
    writer.Flush();
}
Dim price As [Double] = 9.95
Dim [date] As New DateTime(2004, 5, 20)
        
Using writer As XmlWriter = XmlWriter.Create("data.xml")
  writer.WriteStartElement("book")
  writer.WriteStartAttribute("pub-date")
  writer.WriteValue([date])
  writer.WriteEndAttribute()
            
  writer.WriteStartElement("price")
  writer.WriteValue(price)
  writer.WriteEndElement()
            
  writer.WriteEndElement()
  writer.Flush()
End Using

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(String)

寫入 String 值。Writes a String value.

public:
 virtual void WriteValue(System::String ^ value);
public virtual void WriteValue (string value);
public virtual void WriteValue (string? value);
abstract member WriteValue : string -> unit
override this.WriteValue : string -> unit
Public Overridable Sub WriteValue (value As String)

參數

value
String

要寫入的 String 值。The String value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請使用 WriteStringAsync 方法。For asynchronous operations, use the WriteStringAsync method.

適用於

WriteValue(DateTimeOffset)

寫入 DateTimeOffset 值。Writes a DateTimeOffset value.

public:
 virtual void WriteValue(DateTimeOffset value);
public virtual void WriteValue (DateTimeOffset value);
abstract member WriteValue : DateTimeOffset -> unit
override this.WriteValue : DateTimeOffset -> unit
Public Overridable Sub WriteValue (value As DateTimeOffset)

參數

value
DateTimeOffset

要寫入的 DateTimeOffset 值。The DateTimeOffset value to write.

例外狀況

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(DateTime)

寫入 DateTime 值。Writes a DateTime value.

public:
 virtual void WriteValue(DateTime value);
public virtual void WriteValue (DateTime value);
abstract member WriteValue : DateTime -> unit
override this.WriteValue : DateTime -> unit
Public Overridable Sub WriteValue (value As DateTime)

參數

value
DateTime

要寫入的 DateTime 值。The DateTime value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

範例

下列範例會使用具類型的資料來寫入書籍節點。The following example writes a book node using typed data.

Double price = 9.95;
DateTime date = new DateTime(2004, 5, 20);

using (XmlWriter writer = XmlWriter.Create("data.xml"))
{
    writer.WriteStartElement("book");
    writer.WriteStartAttribute("pub-date");
    writer.WriteValue(date);
    writer.WriteEndAttribute();

    writer.WriteStartElement("price");
    writer.WriteValue(price);
    writer.WriteEndElement();

    writer.WriteEndElement();
    writer.Flush();
}
Dim price As [Double] = 9.95
Dim [date] As New DateTime(2004, 5, 20)
        
Using writer As XmlWriter = XmlWriter.Create("data.xml")
  writer.WriteStartElement("book")
  writer.WriteStartAttribute("pub-date")
  writer.WriteValue([date])
  writer.WriteEndAttribute()
            
  writer.WriteStartElement("price")
  writer.WriteValue(price)
  writer.WriteEndElement()
            
  writer.WriteEndElement()
  writer.Flush()
End Using

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Boolean)

寫入 Boolean 值。Writes a Boolean value.

public:
 virtual void WriteValue(bool value);
public virtual void WriteValue (bool value);
abstract member WriteValue : bool -> unit
override this.WriteValue : bool -> unit
Public Overridable Sub WriteValue (value As Boolean)

參數

value
Boolean

要寫入的 Boolean 值。The Boolean value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於

WriteValue(Decimal)

寫入 Decimal 值。Writes a Decimal value.

public:
 virtual void WriteValue(System::Decimal value);
public virtual void WriteValue (decimal value);
abstract member WriteValue : decimal -> unit
override this.WriteValue : decimal -> unit
Public Overridable Sub WriteValue (value As Decimal)

參數

value
Decimal

要寫入的 Decimal 值。The Decimal value to write.

例外狀況

指定了無效的值。An invalid value was specified.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

這個方法會採用 common language runtime 物件,並使用 XML 架構定義語言 (XSD) 資料類型轉換規則,將輸入值轉換為所需的輸出類型。This method takes the common language runtime object and converts the input value to the desired output type using the XML Schema definition language (XSD) data type conversion rules.

呼叫 WriteValue 方法時,XmlWriter 會根據 XML 結構描述 (XSD) 資料型別規則將值轉換成其字串表示,並使用 WriteString 方法將其寫出。When the WriteValue method is called, the XmlWriter converts the value to its string representations according to the XML Schema (XSD) data type rules and writes it out using the WriteString method.

如果連續多次呼叫 WriteValue,則不會使用空格分隔各個值。If WriteValue is called multiple times in succession, the values are not delimited by a space. 您必須在呼叫 WriteWhitespace 之間呼叫 WriteValue,以插入泛空白字元。You must call WriteWhitespace between calls to WriteValue to insert white space. 將陣列型別傳遞至多載 XmlWriter.WriteValue(Object) ,以寫出相異值的陣列。Pass an array type to the XmlWriter.WriteValue(Object) overload to write out an array of distinct values.

如果在只輸出文字的實例上呼叫這個方法 XmlWriter ,則會將具類型的值序列化為文字。If this method is called on an XmlWriter instance that outputs text-only, the typed value is serialized to text.

若為非同步作業,請將這個方法的傳回值轉換成字串,然後使用 WriteStringAsync 方法。For asynchronous operations, convert the return value of this method to a string and use the WriteStringAsync method.

適用於