XmlSerializer.Serialize Method (XmlWriter, Object)
Assembly: System.Xml (in System.Xml.dll)
The Serialize method converts the public fields and read/write properties of an object into XML. It does not convert methods, indexers, private fields, or read-only properties. To serialize all an object's fields and properties, both public and private, use the BinaryFormatter.
The following example serializes an object using an XmlWriter.
<?xml version="1.0"?> <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com"> <inventory:ItemName>Widget</inventory:ItemName> <inventory:Description>Regular Widget</inventory:Description> <money:UnitPrice>2.3</money:UnitPrice> <inventory:Quantity>10</inventory:Quantity> <money:LineTotal>23</money:LineTotal> </OrderedItem>
Available since 4.5
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1