using System.Xml; using umbraco; using umbraco.cms.businesslogic.datatype; namespace umbraco.editorControls { /// /// Overrides the object to return the value as XML. /// public class CsvToXmlData : umbraco.cms.businesslogic.datatype.DefaultData { /// /// The separators to split the delimited string. /// private string[] separator; /// /// Name for the root node. /// private string rootName; /// /// Name for the element/node that contains the value. /// private string elementName; /// /// Initializes a new instance of the class. /// /// Type of the data. public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType) : this(dataType, "values") { } /// /// Initializes a new instance of the class. /// /// Type of the data. /// Name of the root. public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName) : this(dataType, rootName, "value") { } /// /// Initializes a new instance of the class. /// /// Type of the data. /// Name of the root. /// Name of the element. public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName, string elementName) : this(dataType, rootName, elementName, new[] { "," }) { } /// /// Initializes a new instance of the class. /// /// Type of the data. /// Name of the root. /// Name of the element. /// The separator. public CsvToXmlData(umbraco.cms.businesslogic.datatype.BaseDataType dataType, string rootName, string elementName, string[] separator) : base(dataType) { this.rootName = rootName; this.elementName = elementName; this.separator = separator; } /// /// Converts the data value to XML. /// /// The data to convert to XML. /// Returns the data value as an XmlNode public override XmlNode ToXMl(XmlDocument data) { // check that the value isn't null if (this.Value != null) { // split the CSV data into an XML document. var xml = xmlHelper.Split(new XmlDocument(), this.Value.ToString(), this.separator, this.rootName, this.elementName); // return the XML node. return data.ImportNode(xml.DocumentElement, true); } else { // otherwise render the value as default (in CDATA) return base.ToXMl(data); } } } }