Documentation > CMS Template API Library > Util > DeserializeXml(String,Type)
DeserializeXml
Define a class that uses [XmlElement], [XmlAttribute], and other tags and you can then create an object from XML with this method.
public System.Object DeserializeXml(String,Type)
Returns
The un-serialized XML.
Parameters
Name | Description | Type |
---|---|---|
xml | The XML file to deserialize of specified object type | System.String |
objType | Object of specified type used to deserialize an instance of XML | System.Type |
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); //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> //-- deserialize -- UserList deserializedUserListClass = (UserList)Util.DeserializeXml(xml, typeof(UserList)); Out.WriteLine("First User from Xml: " + deserializedUserListClass.Name[0]); Out.WriteLine("Second User from Xml: " + deserializedUserListClass.Name[1]); //output will render the following: First User from Xml: Bob Second User from Xml: Ralph