Documentation > CMS Template API Library > Util > SerializeXml(Object,Boolean)
SerializeXml
Define a class that uses [XmlElement], [XmlAttribute], and other tags and you can then serialize an instance of that class to XML with this method.
public System.String SerializeXml(Object,Boolean)
Returns
The serialized XML.
Parameters
Name | Description | Type |
---|---|---|
obj | Object of specified type used to serialize an instance to XML | System.Object |
serializeEntitiesAsXml | Optional: Set to true to un-escape characters ๸ to Default is false; | System.Boolean |
Code Example
C#
Sample:
//create the class you will use. (system/library/userlist.cs) public class UserList { [XmlElement] public List<string> Name { get; set; } public UserList() { Name = new List<string>(); } } //-- serialize -- List<string> nameList = new List<string>(); nameList.Add("Bob"); nameList.Add("Ralph"); UserList userListClass = new UserList() { Name = nameList }; string xml = Util.SerializeXml(userListClass); Out.WriteLine(xml); //output will render the following: <?xml version="1.0"?> <UserList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Name>Bob</Name> <Name>Ralph</Name> </UserList>