using System; using System.Xml; using System.Xml.Linq; namespace Umbraco.Core.Models { public static class PropertyExtensions { /// /// Creates the xml representation for the object /// /// to generate xml for /// Xml of the property and its value public static XElement ToXml(this Property property) { string nodeName = property.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true); var xd = new XmlDocument(); XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, ""); XmlNode child = property.PropertyType.DataTypeDatabaseType == DataTypeDatabaseType.Ntext ? xd.CreateCDataSection(property.Value.ToString()) as XmlNode : xd.CreateTextNode(property.Value.ToString()); xmlNode.AppendChild(child); //TODO Revisit this by correcting test setup or refactoring DefaultData class to use PetaPoco instead of SqlHelper. //This seems to fail during testing //xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd)); var element = xmlNode.GetXElement(); return element; } } }