/// <summary> /// Iterates over the NameValueCollection, appending each entry to an XmlTextNode. /// </summary> /// <param name="rootName">The name of the root node of the XmlDocument.</param> /// <param name="nvc">The NameValueCollection to be converted.</param> /// <returns>Returns a XPathNodeIterator object that represents the NameValueCollection.</returns> private static XPathNodeIterator ConvertNameValueCollectionToXPathNodeIterator(string rootName, NameValueCollection nvc) { var xd = new XmlDocument(); xd.LoadXml(string.Concat("<", rootName, "/>")); if (nvc != null) { try { for (int i = 0; i < nvc.Count; i++) { var node = XmlHelper.AddCDataNode(xd, nvc.GetKey(i), nvc.Get(i)); xd.DocumentElement.AppendChild(node); } } catch (Exception ex) { xd.DocumentElement.AppendChild(XmlHelper.AddTextNode(xd, "error", ex.Message)); } } else { xd.DocumentElement.AppendChild(XmlHelper.AddTextNode(xd, "error", string.Concat("The ", rootName, " object is empty."))); } return(xd.CreateNavigator().Select("/")); }
/// <summary> /// Gets the Enum of the supplied type and returns its attribute values as a ListItem /// </summary> /// <param name="assemblyName">Full name of the assembly containing the enum</param> /// <param name="typeName">The enum's type name</param> /// <returns>List of ListItems representing the Enum's attribute values</returns> public static XPathNodeIterator GetEnumListAttributeValues(string assemblyName, string typeName) { if (!assemblyName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) { assemblyName += ".dll"; } var assembly = Helper.IO.GetAssembly(assemblyName); var type = assembly.GetType(typeName); var enumListItems = EnumHelper.GetEnumListAttributeValues(type); // create the XML document var xd = new XmlDocument(); xd.LoadXml("<ListItems/>"); // loop through each of the directories foreach (var enumListItem in enumListItems) { var enumNode = XmlHelper.AddTextNode(xd, "ListItem", ""); enumNode.Attributes.Append(XmlHelper.AddAttribute(xd, "Text", enumListItem.Text)); enumNode.Attributes.Append(XmlHelper.AddAttribute(xd, "Value", enumListItem.Value)); enumNode.Attributes.Append(XmlHelper.AddAttribute(xd, "Enabled", enumListItem.Enabled.ToString())); // add the node to the XML document xd.DocumentElement.AppendChild(enumNode); } // return the XML document return(xd.CreateNavigator().Select("/ListItems")); }
public XmlElement ToXml(XmlDocument xd) { XmlElement doc = xd.CreateElement("Stylesheet"); doc.AppendChild(XmlHelper.AddTextNode(xd, "Name", this.Text)); doc.AppendChild(XmlHelper.AddTextNode(xd, "FileName", this.Filename)); doc.AppendChild(XmlHelper.AddCDataNode(xd, "Content", this.Content)); if (this.Properties.Length > 0) { XmlElement props = xd.CreateElement("Properties"); foreach (StylesheetProperty sp in this.Properties) { XmlElement prop = xd.CreateElement("Property"); prop.AppendChild(XmlHelper.AddTextNode(xd, "Name", sp.Text)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Alias", sp.Alias)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Value", sp.value)); props.AppendChild(prop); } doc.AppendChild(props); } return(doc); }
public XmlNode ToXml(XmlDocument xmlDocument) { var xmlNode = xmlDocument.CreateElement("reputation"); xmlNode.AppendChild(XmlHelper.AddTextNode(xmlDocument, "current", Total.ToString())); xmlNode.AppendChild(XmlHelper.AddCDataNode(xmlDocument, "total", Current.ToString())); return(xmlNode); }
/// <summary> /// Converts the Request.Cookies object into a XPathNodeIterator object. /// </summary> /// <returns>Returns a XPathNodeIterator object that represents the Request.Cookies object.</returns> public static XPathNodeIterator Cookies() { var xd = new XmlDocument(); xd.LoadXml("<Request.Cookies/>"); if (HttpContext.Current.Request.Cookies != null) { try { var cookies = HttpContext.Current.Request.Cookies; for (int i = 0; i < cookies.Count; i++) { var cookie = cookies.Get(i); var node = XmlHelper.AddTextNode(xd, "cookie", string.Empty); node.Attributes.Append(XmlHelper.AddAttribute(xd, "name", cookie.Name)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "domain", cookie.Domain)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "expires", cookie.Expires.ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "hasKeys", cookie.HasKeys.ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "httpOnly", cookie.HttpOnly.ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "path", cookie.Path)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "secure", cookie.Secure.ToString())); for (int j = 0; j < cookie.Values.Count; j++) { var value = XmlHelper.AddTextNode(xd, "value", cookie.Values.Get(j)); if (cookie.HasKeys) { value.Attributes.Append(XmlHelper.AddAttribute(xd, "name", cookie.Values.GetKey(j))); } node.AppendChild(value); } xd.DocumentElement.AppendChild(node); } } catch (Exception ex) { xd.DocumentElement.AppendChild(XmlHelper.AddTextNode(xd, "error", ex.Message)); } } else { xd.DocumentElement.AppendChild(XmlHelper.AddTextNode(xd, "error", string.Concat("The Request.Cookies object is empty."))); } return(xd.CreateNavigator().Select("/")); }
public static XmlNode ParseStringToXmlNode(string value) { XmlDocument doc = new XmlDocument(); XmlNode node = XmlHelper.AddTextNode(doc, "error", ""); try { doc.LoadXml(value); return(doc.SelectSingleNode(".")); } catch { return(node); } }
/// <summary> /// Appends the property editor. /// </summary> /// <param name="xd">The XML document.</param> /// <param name="propertyEditor">The property editor.</param> internal static void AppendPropertyEditor(XmlDocument xd, IDataType propertyEditor) { var nodePropertyEditor = XmlHelper.AddTextNode(xd, "PropertyEditor", string.Empty); nodePropertyEditor.Attributes.Append(XmlHelper.AddAttribute(xd, "id", propertyEditor.Id.ToString())); nodePropertyEditor.Attributes.Append(XmlHelper.AddAttribute(xd, "name", propertyEditor.DataTypeName)); // add the property-editor node to the XmlDocument. if (xd.DocumentElement != null) { xd.DocumentElement.AppendChild(nodePropertyEditor); } else { xd.AppendChild(nodePropertyEditor); } }
private XmlDocument ResultsAsXml(IEnumerable <SearchResult> results) { var result = new XmlDocument(); result.LoadXml("<results/>"); foreach (var r in results) { var x = XmlHelper.AddTextNode(result, "result", ""); x.Attributes.Append(XmlHelper.AddAttribute(result, "id", r.Id.ToString())); x.Attributes.Append(XmlHelper.AddAttribute(result, "title", r.Fields["nodeName"])); x.Attributes.Append(XmlHelper.AddAttribute(result, "author", r.Fields["writerName"])); x.Attributes.Append(XmlHelper.AddAttribute(result, "changeDate", r.Fields["updateDate"])); result.DocumentElement.AppendChild(x); } return(result); }
public bool Execute(string packageName, XmlNode xmlData) { var hostname = xmlData.Attributes["host"].Value; if (string.IsNullOrEmpty(hostname)) { return(false); } var xdoc = XmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig); xdoc.PreserveWhitespace = true; var xn = xdoc.SelectSingleNode("//feedProxy"); if (xn != null) { var insert = true; if (xn.HasChildNodes) { foreach (XmlNode node in xn.SelectNodes("//allow")) { if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname) { insert = false; } } } if (insert) { var newHostname = XmlHelper.AddTextNode(xdoc, "allow", string.Empty); newHostname.Attributes.Append(XmlHelper.AddAttribute(xdoc, "host", hostname)); xn.AppendChild(newHostname); xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); return(true); } } return(false); }
public XmlElement ToXml(XmlDocument xd) { XmlElement doc = xd.CreateElement("Template"); doc.AppendChild(XmlHelper.AddTextNode(xd, "Name", this.Text)); doc.AppendChild(XmlHelper.AddTextNode(xd, "Alias", this.Alias)); if (this.MasterTemplate != 0) { doc.AppendChild(XmlHelper.AddTextNode(xd, "Master", new Template(this.MasterTemplate).Alias)); } else { doc.AppendChild(XmlHelper.AddTextNode(xd, "Master", "")); } doc.AppendChild(XmlHelper.AddCDataNode(xd, "Design", this.Design)); return(doc); }
private XmlElement CreateTaskNode(Task t, XmlDocument xd) { var d = new Document(t.Node.Id); var x = d.ToPreviewXml(xd);// xd.CreateNode(XmlNodeType.Element, "node", ""); var xTask = xd.CreateElement("task"); xTask.SetAttributeNode(XmlHelper.AddAttribute(xd, "Id", t.Id.ToString())); xTask.SetAttributeNode(XmlHelper.AddAttribute(xd, "Date", t.Date.ToString("s"))); xTask.SetAttributeNode(XmlHelper.AddAttribute(xd, "NodeId", t.Node.Id.ToString())); xTask.SetAttributeNode(XmlHelper.AddAttribute(xd, "TotalWords", cms.businesslogic.translation.Translation.CountWords(d.Id).ToString())); xTask.AppendChild(XmlHelper.AddCDataNode(xd, "Comment", t.Comment)); string protocol = GlobalSettings.UseSSL ? "https" : "http"; xTask.AppendChild(XmlHelper.AddTextNode(xd, "PreviewUrl", protocol + "://" + Request.ServerVariables["SERVER_NAME"] + SystemDirectories.Umbraco + "/translation/preview.aspx?id=" + t.Id.ToString())); // d.XmlPopulate(xd, ref x, false); xTask.AppendChild(x); return(xTask); }
/// <summary> /// Gets a list of group names from the specific member. /// </summary> /// <param name="memberId">Member's Id</param> /// <returns> /// A node-set of all the member-groups from the specific member /// </returns> public static XPathNodeIterator GetGroupsByMemberId(int memberId) { try { var xd = new XmlDocument(); xd.LoadXml("<memberGroups/>"); var member = new Member(memberId); foreach (var group in Roles.GetRolesForUser(member.LoginName)) { var memberGroupNode = XmlHelper.AddTextNode(xd, "memberGroup", group); xd.DocumentElement.AppendChild(memberGroupNode); } return(xd.CreateNavigator().Select("/memberGroups")); } catch (Exception ex) { return(ex.ToXPathNodeIterator()); } }
/// <summary> /// Gets the usernames of all the members in the specified group. /// </summary> /// <param name="groupName">Name of the member group.</param> /// <returns>Returns a list of all the member names.</returns> public static XPathNodeIterator GetMembersByGroupName(string groupName) { try { var xd = new XmlDocument(); xd.LoadXml("<members/>"); if (!string.IsNullOrEmpty(groupName)) { foreach (var memberName in Roles.GetUsersInRole(groupName)) { var memberNode = XmlHelper.AddTextNode(xd, "member", memberName); xd.DocumentElement.AppendChild(memberNode); } } return(xd.CreateNavigator().Select("/members")); } catch (Exception ex) { return(ex.ToXPathNodeIterator()); } }
/// <summary> /// Splits the specified delimited string into an XML document. /// </summary> /// <param name="xml">The XML document.</param> /// <param name="data">The delimited string data.</param> /// <param name="separator">The separator.</param> /// <param name="rootName">Name of the root node.</param> /// <param name="elementName">Name of the element node.</param> /// <returns>Returns an <c>System.Xml.XmlDocument</c> representation of the delimited string data.</returns> public static XmlDocument Split(XmlDocument xml, string data, string[] separator, string rootName, string elementName) { // load new XML document. xml.LoadXml(string.Concat("<", rootName, "/>")); // get the data-value, check it isn't empty. if (!string.IsNullOrEmpty(data)) { // explode the values into an array var values = data.Split(separator, StringSplitOptions.None); // loop through the array items. foreach (string value in values) { // add each value to the XML document. var xn = XmlHelper.AddTextNode(xml, elementName, value); xml.DocumentElement.AppendChild(xn); } } // return the XML node. return(xml); }
/// <summary> /// Get an xmlrepresentation of the macro, used for exporting the macro to a package for distribution /// </summary> /// <param Name="xd">Current xmldocument context</param> /// <returns>An xmlrepresentation of the macro</returns> public XmlElement ToXml(XmlDocument xd) { XmlElement doc = xd.CreateElement("macro"); // info section doc.AppendChild(XmlHelper.AddTextNode(xd, "Name", this.Name)); doc.AppendChild(XmlHelper.AddTextNode(xd, "alias", this.Alias)); doc.AppendChild(XmlHelper.AddTextNode(xd, "scriptType", this.Type)); doc.AppendChild(XmlHelper.AddTextNode(xd, "scriptAssembly", this.Assembly)); doc.AppendChild(XmlHelper.AddTextNode(xd, "xslt", this.Xslt)); doc.AppendChild(XmlHelper.AddTextNode(xd, "useInEditor", this.UseInEditor.ToString())); doc.AppendChild(XmlHelper.AddTextNode(xd, "refreshRate", this.RefreshRate.ToString())); // properties XmlElement props = xd.CreateElement("properties"); foreach (MacroProperty p in this.Properties) { props.AppendChild(p.ToXml(xd)); } doc.AppendChild(props); return(doc); }
/// <summary> /// Appends the user to the XML document. /// </summary> /// <param name="xd">The XML document.</param> /// <param name="user">The user.</param> internal static void AppendUser(XmlDocument xd, User user) { var node = XmlHelper.AddTextNode(xd, "User", string.Empty); node.Attributes.Append(XmlHelper.AddAttribute(xd, "id", user.Id.ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "name", user.Name)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "loginName", user.LoginName)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "email", user.Email)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "language", user.Language)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "userTypeAlias", user.UserType.Alias)); node.Attributes.Append(XmlHelper.AddAttribute(xd, "isAdmin", user.IsAdmin().ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "startNodeId", user.StartNodeId.ToString())); node.Attributes.Append(XmlHelper.AddAttribute(xd, "startMediaId", user.StartMediaId.ToString())); // add the user node to the XmlDocument. if (xd.DocumentElement != null) { xd.DocumentElement.AppendChild(node); } else { xd.AppendChild(node); } }
public XmlElement ToXml(XmlDocument xd) { XmlElement doc = xd.CreateElement("DocumentType"); // info section XmlElement info = xd.CreateElement("Info"); doc.AppendChild(info); info.AppendChild(XmlHelper.AddTextNode(xd, "Name", Text)); info.AppendChild(XmlHelper.AddTextNode(xd, "Alias", Alias)); info.AppendChild(XmlHelper.AddTextNode(xd, "Icon", IconUrl)); info.AppendChild(XmlHelper.AddTextNode(xd, "Thumbnail", Thumbnail)); info.AppendChild(XmlHelper.AddTextNode(xd, "Description", Description)); // templates XmlElement allowed = xd.CreateElement("AllowedTemplates"); foreach (template.Template t in allowedTemplates) { allowed.AppendChild(XmlHelper.AddTextNode(xd, "Template", t.Alias)); } info.AppendChild(allowed); if (DefaultTemplate != 0) { info.AppendChild( XmlHelper.AddTextNode(xd, "DefaultTemplate", new template.Template(DefaultTemplate).Alias)); } else { info.AppendChild(XmlHelper.AddTextNode(xd, "DefaultTemplate", "")); } // structure XmlElement structure = xd.CreateElement("Structure"); doc.AppendChild(structure); foreach (int cc in AllowedChildContentTypeIDs) { structure.AppendChild(XmlHelper.AddTextNode(xd, "DocumentType", new DocumentType(cc).Alias)); } // generic properties XmlElement pts = xd.CreateElement("GenericProperties"); foreach (PropertyType pt in PropertyTypes) { XmlElement ptx = xd.CreateElement("GenericProperty"); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Name", pt.Name)); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Alias", pt.Alias)); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Type", pt.DataTypeDefinition.DataType.Id.ToString())); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Tab", Tab.GetCaptionById(pt.TabId))); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Mandatory", pt.Mandatory.ToString())); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Validation", pt.ValidationRegExp)); ptx.AppendChild(XmlHelper.AddCDataNode(xd, "Description", pt.Description)); pts.AppendChild(ptx); } doc.AppendChild(pts); // tabs XmlElement tabs = xd.CreateElement("Tabs"); foreach (TabI t in getVirtualTabs) { XmlElement tabx = xd.CreateElement("Tab"); tabx.AppendChild(XmlHelper.AddTextNode(xd, "Id", t.Id.ToString())); tabx.AppendChild(XmlHelper.AddTextNode(xd, "Caption", t.Caption)); tabs.AppendChild(tabx); } doc.AppendChild(tabs); return(doc); }
/// <summary> /// Appends the type of the content. /// </summary> /// <param name="xd">The XML document.</param> /// <param name="elementName">Name of the element.</param> /// <param name="contentType">The content type.</param> /// <param name="includeTabs">if set to <c>true</c> [include tabs].</param> /// <param name="includePropertyTypes">if set to <c>true</c> [include property types].</param> internal static void AppendContentType(XmlDocument xd, string elementName, ContentType contentType, bool includeTabs, bool includePropertyTypes) { var nodeContentType = XmlHelper.AddTextNode(xd, elementName, string.Empty); nodeContentType.AppendChild(XmlHelper.AddCDataNode(xd, "description", contentType.Description)); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "id", contentType.Id.ToString())); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", contentType.Text)); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", contentType.Alias)); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "image", contentType.Image)); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "thumbnail", contentType.Thumbnail)); //// nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "master", contentType.MasterContentType.ToString())); nodeContentType.Attributes.Append(XmlHelper.AddAttribute(xd, "hasChildren", contentType.HasChildren.ToString())); if (includeTabs) { var tabs = contentType.getVirtualTabs; if (tabs != null && tabs.Length > 0) { var nodeTabs = XmlHelper.AddTextNode(xd, "tabs", string.Empty); foreach (var tab in tabs) { var nodeTab = XmlHelper.AddTextNode(xd, "tab", string.Empty); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "id", tab.Id.ToString())); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "caption", tab.Caption)); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "sortOrder", tab.SortOrder.ToString())); nodeTabs.AppendChild(nodeTab); } nodeContentType.AppendChild(nodeTabs); } } if (includePropertyTypes) { var propertyTypes = contentType.PropertyTypes; if (propertyTypes != null && propertyTypes.Count > 0) { var nodePropertyTypes = XmlHelper.AddTextNode(xd, "propertyTypes", string.Empty); foreach (PropertyType propertyType in propertyTypes) { var nodePropertyType = XmlHelper.AddTextNode(xd, "propertyType", string.Empty); nodePropertyType.AppendChild(XmlHelper.AddCDataNode(xd, "description", propertyType.Description)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "id", propertyType.Id.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", propertyType.Name)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", propertyType.Alias)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "contentTypeId", propertyType.ContentTypeId.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", propertyType.Description)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "mandatory", propertyType.Mandatory.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "sortOrder", propertyType.SortOrder.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "tabId", propertyType.PropertyTypeGroup.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "regEx", propertyType.ValidationRegExp)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "dataTypeId", propertyType.DataTypeDefinition.Id.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "dataTypeGuid", propertyType.DataTypeDefinition.UniqueId.ToString())); nodePropertyTypes.AppendChild(nodePropertyType); } nodeContentType.AppendChild(nodePropertyTypes); } } // add the content-type node to the XmlDocument. if (xd.DocumentElement != null) { xd.DocumentElement.AppendChild(nodeContentType); } else { xd.AppendChild(nodeContentType); } }
/// <summary> /// Appends the type of the document. /// </summary> /// <param name="xd">The XML document.</param> /// <param name="docType">The document type.</param> /// <param name="includeTabs">if set to <c>true</c> [include tabs].</param> /// <param name="includePropertyTypes">if set to <c>true</c> [include property types].</param> /// <param name="includeAllowedTemplates">if set to <c>true</c> [include allowed templates].</param> internal static void AppendDocumentType(XmlDocument xd, DocumentType docType, bool includeTabs, bool includePropertyTypes, bool includeAllowedTemplates) { var nodeDocType = XmlHelper.AddTextNode(xd, "DocumentType", string.Empty); nodeDocType.AppendChild(XmlHelper.AddCDataNode(xd, "description", docType.Description)); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "id", docType.Id.ToString())); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", docType.Text)); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", docType.Alias)); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "image", docType.Image)); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "thumbnail", docType.Thumbnail)); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "master", docType.MasterContentType.ToString())); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "hasChildren", docType.HasChildren.ToString())); nodeDocType.Attributes.Append(XmlHelper.AddAttribute(xd, "defaultTemplate", docType.DefaultTemplate.ToString())); if (includeTabs) { var tabs = docType.getVirtualTabs; if (tabs != null && tabs.Length > 0) { var nodeTabs = XmlHelper.AddTextNode(xd, "tabs", string.Empty); foreach (var tab in tabs) { var nodeTab = XmlHelper.AddTextNode(xd, "tab", string.Empty); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "id", tab.Id.ToString())); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "caption", tab.Caption)); nodeTab.Attributes.Append(XmlHelper.AddAttribute(xd, "sortOrder", tab.SortOrder.ToString())); nodeTabs.AppendChild(nodeTab); } nodeDocType.AppendChild(nodeTabs); } } if (includePropertyTypes) { var propertyTypes = docType.PropertyTypes; if (propertyTypes != null && propertyTypes.Count > 0) { var nodePropertyTypes = XmlHelper.AddTextNode(xd, "propertyTypes", string.Empty); foreach (var propertyType in propertyTypes) { var nodePropertyType = XmlHelper.AddTextNode(xd, "propertyType", string.Empty); nodePropertyType.AppendChild(XmlHelper.AddCDataNode(xd, "description", propertyType.Description)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "id", propertyType.Id.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", propertyType.Name)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", propertyType.Alias)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "contentTypeId", propertyType.ContentTypeId.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "name", propertyType.Description)); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "mandatory", propertyType.Mandatory.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "sortOrder", propertyType.SortOrder.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "tabId", propertyType.TabId.ToString())); nodePropertyType.Attributes.Append(XmlHelper.AddAttribute(xd, "regEx", propertyType.ValidationRegExp)); nodePropertyTypes.AppendChild(nodePropertyType); } nodeDocType.AppendChild(nodePropertyTypes); } } if (includeAllowedTemplates) { var templates = docType.allowedTemplates; if (templates != null && templates.Length > 0) { var nodeTemplates = XmlHelper.AddTextNode(xd, "allowedTemplates", string.Empty); foreach (var template in templates) { var nodeTemplate = XmlHelper.AddTextNode(xd, "template", string.Empty); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "id", template.Id.ToString())); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "name", template.Text)); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", template.Alias)); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "masterPageFile", template.TemplateFilePath)); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "masterTemplate", template.MasterTemplate.ToString())); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "hasChildren", template.HasChildren.ToString())); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "sortOrder", template.sortOrder.ToString())); nodeTemplate.Attributes.Append(XmlHelper.AddAttribute(xd, "isDefaultTemplate", (template.Id == docType.DefaultTemplate).ToString())); nodeTemplates.AppendChild(nodeTemplate); } nodeDocType.AppendChild(nodeTemplates); } } if (xd.DocumentElement != null) { xd.DocumentElement.AppendChild(nodeDocType); } else { xd.AppendChild(nodeDocType); } }
/// <summary> /// Converts the data value to XML. /// </summary> /// <param name="data">The data to convert to XML.</param> /// <returns>Returns the XML node for the data-type's value.</returns> public override XmlNode ToXMl(XmlDocument data) { // check that the value isn't null if (this.Value != null) { var value = this.Value.ToString(); var xd = new XmlDocument(); // if the value is coming from a translation task, it will always be XML if (Helper.Xml.CouldItBeXml(value)) { xd.LoadXml(value); return(data.ImportNode(xd.DocumentElement, true)); } // load the values into a string array/list. var deserializer = new JavaScriptSerializer(); var values = deserializer.Deserialize <List <string[]> >(value); if (values != null && values.Count > 0) { // load the values into an XML document. xd.LoadXml("<TextstringArray/>"); // load the config options if (this.options.ShowColumnLabels && !string.IsNullOrWhiteSpace(this.options.ColumnLabels)) { var xlabels = xd.CreateElement("labels"); // loop through the labels. foreach (var label in this.options.ColumnLabels.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { // add each label to the XML document. var xlabel = XmlHelper.AddTextNode(xd, "label", label); xlabels.AppendChild(xlabel); } xd.DocumentElement.AppendChild(xlabels); } // loop through the list/array items. foreach (var row in values) { // add each row to the XML document. var xrow = xd.CreateElement("values"); foreach (var item in row) { // add each value to the XML document. var xvalue = XmlHelper.AddTextNode(xd, "value", item); xrow.AppendChild(xvalue); } xd.DocumentElement.AppendChild(xrow); } // return the XML node. return(data.ImportNode(xd.DocumentElement, true)); } } // otherwise render the value as default (in CDATA) return(base.ToXMl(data)); }
public static PackageInstance MakeNew(string Name, string dataSource) { Reload(dataSource); int maxId = 1; // Find max id foreach (XmlNode n in Source.SelectNodes("packages/package")) { if (int.Parse(n.Attributes.GetNamedItem("id").Value) >= maxId) { maxId = int.Parse(n.Attributes.GetNamedItem("id").Value) + 1; } } XmlElement instance = Source.CreateElement("package"); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "id", maxId.ToString())); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "version", "")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "url", "")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "name", Name)); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "folder", Guid.NewGuid().ToString())); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "packagepath", "")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "repositoryGuid", "")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "iconUrl", "")); //set to current version instance.Attributes.Append(XmlHelper.AddAttribute(Source, "umbVersion", UmbracoVersion.Current.ToString(3))); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "packageGuid", Guid.NewGuid().ToString())); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "hasUpdate", "false")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "enableSkins", "false")); instance.Attributes.Append(XmlHelper.AddAttribute(Source, "skinRepoGuid", "")); XmlElement license = Source.CreateElement("license"); license.InnerText = "MIT License"; license.Attributes.Append(XmlHelper.AddAttribute(Source, "url", "http://opensource.org/licenses/MIT")); instance.AppendChild(license); XmlElement author = Source.CreateElement("author"); author.InnerText = ""; author.Attributes.Append(XmlHelper.AddAttribute(Source, "url", "")); instance.AppendChild(author); instance.AppendChild(XmlHelper.AddTextNode(Source, "readme", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "actions", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "datatypes", "")); XmlElement content = Source.CreateElement("content"); content.InnerText = ""; content.Attributes.Append(XmlHelper.AddAttribute(Source, "nodeId", "")); content.Attributes.Append(XmlHelper.AddAttribute(Source, "loadChildNodes", "false")); instance.AppendChild(content); instance.AppendChild(XmlHelper.AddTextNode(Source, "templates", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "stylesheets", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "documenttypes", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "macros", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "files", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "languages", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "dictionaryitems", "")); instance.AppendChild(XmlHelper.AddTextNode(Source, "loadcontrol", "")); Source.SelectSingleNode("packages").AppendChild(instance); Source.Save(dataSource); var retVal = data.Package(maxId, dataSource); return(retVal); }
public static void Save(PackageInstance package, string dataSource) { Reload(dataSource); var xmlDef = GetFromId(package.Id, dataSource, false); XmlHelper.SetAttribute(Source, xmlDef, "name", package.Name); XmlHelper.SetAttribute(Source, xmlDef, "version", package.Version); XmlHelper.SetAttribute(Source, xmlDef, "url", package.Url); XmlHelper.SetAttribute(Source, xmlDef, "packagepath", package.PackagePath); XmlHelper.SetAttribute(Source, xmlDef, "repositoryGuid", package.RepositoryGuid); XmlHelper.SetAttribute(Source, xmlDef, "packageGuid", package.PackageGuid); XmlHelper.SetAttribute(Source, xmlDef, "hasUpdate", package.HasUpdate.ToString()); XmlHelper.SetAttribute(Source, xmlDef, "enableSkins", package.EnableSkins.ToString()); XmlHelper.SetAttribute(Source, xmlDef, "skinRepoGuid", package.SkinRepoGuid.ToString()); XmlHelper.SetAttribute(Source, xmlDef, "iconUrl", package.IconUrl); if (package.UmbracoVersion != null) { XmlHelper.SetAttribute(Source, xmlDef, "umbVersion", package.UmbracoVersion.ToString(3)); } var licenseNode = xmlDef.SelectSingleNode("license"); if (licenseNode == null) { licenseNode = Source.CreateElement("license"); xmlDef.AppendChild(licenseNode); } licenseNode.InnerText = package.License; XmlHelper.SetAttribute(Source, licenseNode, "url", package.LicenseUrl); var authorNode = xmlDef.SelectSingleNode("author"); if (authorNode == null) { authorNode = Source.CreateElement("author"); xmlDef.AppendChild(authorNode); } authorNode.InnerText = package.Author; XmlHelper.SetAttribute(Source, authorNode, "url", package.AuthorUrl); XmlHelper.SetCDataNode(Source, xmlDef, "readme", package.Readme); XmlHelper.SetInnerXmlNode(Source, xmlDef, "actions", package.Actions); var contentNode = xmlDef.SelectSingleNode("content"); if (contentNode == null) { contentNode = Source.CreateElement("content"); xmlDef.AppendChild(contentNode); } XmlHelper.SetAttribute(Source, contentNode, "nodeId", package.ContentNodeId); XmlHelper.SetAttribute(Source, contentNode, "loadChildNodes", package.ContentLoadChildNodes.ToString()); XmlHelper.SetTextNode(Source, xmlDef, "macros", JoinList(package.Macros, ',')); XmlHelper.SetTextNode(Source, xmlDef, "templates", JoinList(package.Templates, ',')); XmlHelper.SetTextNode(Source, xmlDef, "stylesheets", JoinList(package.Stylesheets, ',')); XmlHelper.SetTextNode(Source, xmlDef, "documenttypes", JoinList(package.Documenttypes, ',')); XmlHelper.SetTextNode(Source, xmlDef, "languages", JoinList(package.Languages, ',')); XmlHelper.SetTextNode(Source, xmlDef, "dictionaryitems", JoinList(package.DictionaryItems, ',')); XmlHelper.SetTextNode(Source, xmlDef, "datatypes", JoinList(package.DataTypes, ',')); var filesNode = xmlDef.SelectSingleNode("files"); if (filesNode == null) { filesNode = Source.CreateElement("files"); xmlDef.AppendChild(filesNode); } filesNode.InnerXml = ""; foreach (var fileStr in package.Files) { if (string.IsNullOrWhiteSpace(fileStr) == false) { filesNode.AppendChild(XmlHelper.AddTextNode(Source, "file", fileStr)); } } XmlHelper.SetTextNode(Source, xmlDef, "loadcontrol", package.LoadControl); Source.Save(dataSource); }
public static XmlElement ToXml(XmlDocument xd, MediaType mt) { if (mt == null) { throw new ArgumentNullException("Mediatype cannot be null"); } if (xd == null) { throw new ArgumentNullException("XmlDocument cannot be null"); } XmlElement doc = xd.CreateElement("MediaType"); // build the info section (name and stuff) XmlElement info = xd.CreateElement("Info"); doc.AppendChild(info); info.AppendChild(XmlHelper.AddTextNode(xd, "Name", mt.Text)); info.AppendChild(XmlHelper.AddTextNode(xd, "Alias", mt.Alias)); info.AppendChild(XmlHelper.AddTextNode(xd, "Icon", mt.IconUrl)); info.AppendChild(XmlHelper.AddTextNode(xd, "Thumbnail", mt.Thumbnail)); info.AppendChild(XmlHelper.AddTextNode(xd, "Description", mt.Description)); // v6 property info.AppendChild(XmlHelper.AddTextNode(xd, "AllowAtRoot", mt.AllowAtRoot.ToString())); XmlElement structure = xd.CreateElement("Structure"); foreach (int child in mt.AllowedChildContentTypeIDs.ToList()) { structure.AppendChild(XmlHelper.AddTextNode(xd, "MediaType", new MediaType(child).Alias)); } doc.AppendChild(structure); // // in v6 - media types can be nested. // if (mt.MasterContentType > 0) { MediaType pmt = new MediaType(mt.MasterContentType); if (pmt != null) { info.AppendChild(XmlHelper.AddTextNode(xd, "Master", pmt.Alias)); } } // stuff in the generic properties tab XmlElement props = xd.CreateElement("GenericProperties"); foreach (PropertyType pt in mt.PropertyTypes) { // we only add properties that arn't in a parent (although media types are flat at the mo) if (pt.ContentTypeId == mt.Id) { XmlElement prop = xd.CreateElement("GenericProperty"); prop.AppendChild(XmlHelper.AddTextNode(xd, "Name", pt.Name)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Alias", pt.Alias)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Type", pt.DataTypeDefinition.DataType.Id.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Definition", pt.DataTypeDefinition.UniqueId.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Tab", ContentType.Tab.GetCaptionById(pt.TabId))); prop.AppendChild(XmlHelper.AddTextNode(xd, "Mandatory", pt.Mandatory.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Validation", pt.ValidationRegExp)); prop.AppendChild(XmlHelper.AddCDataNode(xd, "Description", pt.Description)); // add this property to the tree props.AppendChild(prop); } } // add properties to the doc doc.AppendChild(props); // tabs XmlElement tabs = xd.CreateElement("Tabs"); foreach (ContentType.TabI t in mt.getVirtualTabs.ToList()) { //only add tabs that aren't from a master doctype if (t.ContentType == mt.Id) { XmlElement tabx = xd.CreateElement("Tab"); tabx.AppendChild(xmlHelper.addTextNode(xd, "Id", t.Id.ToString())); tabx.AppendChild(xmlHelper.addTextNode(xd, "Caption", t.Caption)); tabx.AppendChild(xmlHelper.addTextNode(xd, "Sort", t.SortOrder.ToString())); tabs.AppendChild(tabx); } } doc.AppendChild(tabs); return(doc); }
public XmlElement ToXml(XmlDocument xd) { XmlElement doc = xd.CreateElement("DocumentType"); // info section XmlElement info = xd.CreateElement("Info"); doc.AppendChild(info); info.AppendChild(XmlHelper.AddTextNode(xd, "Name", GetRawText())); info.AppendChild(XmlHelper.AddTextNode(xd, "Alias", Alias)); info.AppendChild(XmlHelper.AddTextNode(xd, "Icon", IconUrl)); info.AppendChild(XmlHelper.AddTextNode(xd, "Thumbnail", Thumbnail)); info.AppendChild(XmlHelper.AddTextNode(xd, "Description", GetRawDescription())); info.AppendChild(XmlHelper.AddTextNode(xd, "AllowAtRoot", AllowAtRoot.ToString())); //TODO: Add support for mixins! if (this.MasterContentType > 0) { DocumentType dt = new DocumentType(this.MasterContentType); if (dt != null) { info.AppendChild(XmlHelper.AddTextNode(xd, "Master", dt.Alias)); } } // templates XmlElement allowed = xd.CreateElement("AllowedTemplates"); foreach (template.Template t in allowedTemplates) { allowed.AppendChild(XmlHelper.AddTextNode(xd, "Template", t.Alias)); } info.AppendChild(allowed); if (DefaultTemplate != 0) { info.AppendChild( XmlHelper.AddTextNode(xd, "DefaultTemplate", new template.Template(DefaultTemplate).Alias)); } else { info.AppendChild(XmlHelper.AddTextNode(xd, "DefaultTemplate", "")); } // structure XmlElement structure = xd.CreateElement("Structure"); doc.AppendChild(structure); foreach (int cc in AllowedChildContentTypeIDs.ToList()) { structure.AppendChild(XmlHelper.AddTextNode(xd, "DocumentType", new DocumentType(cc).Alias)); } // generic properties XmlElement pts = xd.CreateElement("GenericProperties"); foreach (PropertyType pt in PropertyTypes) { //only add properties that aren't from master doctype if (pt.ContentTypeId == this.Id) { XmlElement ptx = xd.CreateElement("GenericProperty"); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Name", pt.GetRawName())); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Alias", pt.Alias)); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Type", pt.DataTypeDefinition.DataType.Id.ToString())); //Datatype definition guid was added in v4 to enable datatype imports ptx.AppendChild(XmlHelper.AddTextNode(xd, "Definition", pt.DataTypeDefinition.UniqueId.ToString())); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Tab", Tab.GetCaptionById(pt.TabId))); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Mandatory", pt.Mandatory.ToString())); ptx.AppendChild(XmlHelper.AddTextNode(xd, "Validation", pt.ValidationRegExp)); ptx.AppendChild(XmlHelper.AddCDataNode(xd, "Description", pt.GetRawDescription())); pts.AppendChild(ptx); } } doc.AppendChild(pts); // tabs var tabs = xd.CreateElement("Tabs"); foreach (var propertyTypeGroup in PropertyTypeGroups) { //only add tabs that aren't from a master doctype if (propertyTypeGroup.ContentTypeId == this.Id) { var tabx = xd.CreateElement("Tab"); tabx.AppendChild(XmlHelper.AddTextNode(xd, "Id", propertyTypeGroup.Id.ToString())); tabx.AppendChild(XmlHelper.AddTextNode(xd, "Caption", propertyTypeGroup.Name)); tabs.AppendChild(tabx); } } doc.AppendChild(tabs); return(doc); }