Indicates to the System.Xml.Serialization.XmlSerializer that the member must be treated as XML text when the class that contains it is serialized or deserialized.
See Also: XmlTextAttribute Members
The System.Xml.Serialization.XmlTextAttribute belongs to a family of attributes that controls how the System.Xml.Serialization.XmlSerializer serializes and deserializes an object (through its XmlSerializer.Serialize(System.IO.TextWriter, object) and XmlSerializer.Deserialize(System.IO.Stream) methods). For a complete list of similar attributes, see Attributes That Control XML Serialization.
Only one instance of the System.Xml.Serialization.XmlTextAttribute class can be applied in a class.
You can apply the System.Xml.Serialization.XmlTextAttribute to public fields and public read/write properties that return primitive and enumeration types.
You can apply the System.Xml.Serialization.XmlTextAttribute to a field or property that returns an array of strings. You can also apply the attribute to an array of type object but you must set the XmlTextAttribute.Type property to string. In that case, any strings inserted into the array are serialized as XML text.
The System.Xml.Serialization.XmlTextAttribute can also be applied to a field that returns an System.Xml.XmlNode or an array of System.Xml.XmlNode objects.
By default, the System.Xml.Serialization.XmlSerializer serializes a class member as an XML element. However, if you apply the System.Xml.Serialization.XmlTextAttribute to a member, the System.Xml.Serialization.XmlSerializer translates its value into XML text. This means that the value is encoded into the content of an XML element.
The XML Schema Definition Tool (Xsd.exe) occasionally generates the System.Xml.Serialization.XmlTextAttribute when creating classes from an XML Schema definition (XSD) file. This occurs when the schema contains a complexType with mixed content; in that case, the corresponding class contains a member that returns a string array to which the System.Xml.Serialization.XmlTextAttribute is applied. For example, when the Xml Schema Definition tool processes this schema:
Example
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="LinkList" type="LinkList" /> <xs:complexType name="LinkList" mixed="true"> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" name="id" type="xs:int" /> <xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="next" type="LinkList" /> </xs:sequence> </xs:complexType> </xs:schema>
the following class is generated (extra spaces and remarks have been removed):
code reference: XmlTextAttribute#0
For more information about using attributes, see Extending Metadata Using Attributes.
You can use the word XmlText in your code instead of the longer System.Xml.Serialization.XmlTextAttribute.