void ToXml();
void ToXml(bool includeDocHeader,
                     Formatting formatting,
                     EOLType eol);
void ToXml(bool includeDocHeader,
                     Formatting formatting,
                     EOLType eol,
                     XmlSerializationContext context);
  Property Description  
    Method Name ToXML  
    Return The XML data represented by the object  
    Argument - includeDocHeader (Default true) If this is true then then header <?xml version="1.0" ?> is applied to the output (making it a proper XML document as opposed to a snippet.)  
    Argument - formatting (default Formatting.Indented) Indicates how the XML should be formatted true to turn on indenting, false for no formatting.  
    Argument - eol (Default EOLType.CRLF) Indicates the type of End of line token to use, CR or LFCR. Defaults to CR.  
    Argument - context

The XmlSerializationContext object controls the way in which XML is serialized/de-serialized. Its main role is to control the way in which validation is performed and which namespaces are output.
If this is not specified, the a default (XmlSerializationContext.Default global static) instance of the class is used. If you are using several libraries generated from different schemas, or you want to change the way validation is performed for during the lifetime of the application or you are writing multithreaded code, then you should consider creating your own instance(s) of the XmlSerializationContext.

Note: If you are writing a multithreaded app it is highly recommended that you use a different instance of this class on each thread, as access to the static instance is not synchronized. Although read only operations to the static instance (XmlSerializationContext.Default) of the class are thread safe, if the global instance XmlSerializationContext.Default is modified, then this could potentially cause threading problems.

    Description Returns an XML string.  

It will raise an exception if the XML within the object is not invalid, i.e. invalid number of entries in a collection.

The function returns a UNICODE xml string. This means that the document header (if included) will contain just <?xml version="1.0"?>. If 'exotic' characters have been used they will simply be encoded as UNICODE.
It should be noted that, if the string is converted to a single byte representation (1 byte per character) for transmission or writing to disk, then there is a danger that characters will be misrepresented.
See Multi-Language Support for more information.

If a UFT-8 or other encoding is required then use XmlToFile or XmlToStream.