/// <summary> /// /// </summary> /// <param name="xmlDoc"></param> /// <param name="nodeName"></param> public static XmlElement AddRootNode(this XmlDocument xmlDoc, string nodeName) { //let's add the XML declaration section XmlNode xmlnode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); xmlDoc.AppendChild(xmlnode); //let's add the root element XmlElement xmlElem = xmlDoc.CreateElement("", nodeName, ""); xmlDoc.AppendChild(xmlElem); return xmlElem; }
/// <summary> /// Add a new XML element as a child of another node. /// </summary> /// <param name="parent">Node to add new element under</param> /// <param name="name">Name of new element</param> /// <param name="innerText">Text to add with new element</param> /// <returns>New element</returns> public static XmlElement AddElement(this XmlNode parent, string name, string innerText) { XmlElement e = parent.OwnerDocument.CreateElement(name); if(innerText != null) e.InnerText = innerText; parent.AppendChild(e); return e; }
/// <summary> /// Appends a child to a XML node /// </summary> /// <param name = "parentNode">The parent node.</param> /// <param name = "name">The name of the child node.</param> /// <param name = "namespaceUri">The node namespace.</param> /// <returns>The newly cerated XML node</returns> public static XmlNode CreateChildNode(this XmlNode parentNode, string name, string namespaceUri) { var document = (parentNode is XmlDocument ? (XmlDocument) parentNode : parentNode.OwnerDocument); XmlNode node = document.CreateElement(name, namespaceUri); parentNode.AppendChild(node); return node; }
public static XmlElement WithFormattedText(this XmlElement element, string text) { var section = element.OwnerDocument.CreateCDataSection(text); element.AppendChild(section); return element; }
private static XmlElement AppendChild(this XmlElement element, string name) { XmlElement child = element.OwnerDocument.CreateElement(name); element.AppendChild(child); return child; }
private static XmlElement AppendText(this XmlElement element, string text) { XmlText child = element.OwnerDocument.CreateTextNode(text); element.AppendChild(child); return element; }
public static void Write(this XmlElement applyNode, XmlNodeSchema schema) { var xml = applyNode.OwnerDocument; if (xml == null) { return; } if (string.IsNullOrEmpty(schema.Name)) { return; } var node = xml.CreateElement(schema.Name); foreach (string property in schema.Properties) { var value = schema.Properties[property]; if (string.IsNullOrEmpty(value)) { continue; } var attribute = xml.CreateAttribute(property); attribute.Value = value; node.Attributes.Append(attribute); } applyNode.AppendChild(node); if (schema.ChildNodes == null) return; foreach (var childNode in schema.ChildNodes) { Write(node, childNode); } }
public static HtmlNode CreateElementWithHtml(this HtmlNode htmlNode, string name, string html) { HtmlNode element = htmlNode.OwnerDocument.CreateElement(name); element.InnerHtml = html; htmlNode.AppendChild(element); return element; }
public static XmlDocument Create(this XmlDocument xml) { xml = xml ?? new XmlDocument(); var version = xml.CreateXmlDeclaration("1.0", "utf-8", ""); xml.AppendChild(version); return xml; }
/// <summary> /// Adds a CDATA child element /// </summary> /// <param name="node">node to append child</param> /// <param name="nodeName">new child node name</param> /// <param name="cdata">CDATA value</param> /// <exception>If could not create child node</exception> /// <exception>If could not create CDATA node</exception> internal static void XmlAddChildCDATAElem(this XmlNode node, string nodeName, string cdata) { XmlNode newNode = node.OwnerDocument.CreateElement(nodeName); if(newNode == null) return; // Hack workaround to prevent stuff like blank line comments // from consuming more than they should. if(nodeName != "code" && cdata == "\r") cdata = " \r"; node.AppendChild(newNode); Match m = reTrailingCrLfs.Match(cdata); // Move trailing CR/LF's into their own code tag if(m.Success) cdata = cdata.Substring(0, m.Index + 1); XmlNode newCDATANode = node.OwnerDocument.CreateCDataSection( WebUtility.HtmlEncode(cdata)); if(newCDATANode == null) return; newNode.AppendChild(newCDATANode); // Add the node for the trailing CR/LFs if needed if(m.Success) node.XmlAddChildCDATAElem("code", m.Groups[1].Value); }
public static void AppendChildIfNotNull(this XmlNode node, XmlNode childNode) { if (childNode != null) { node.AppendChild(childNode); } }
/// <summary> /// Appends a CData section to a XML node and prefills the provided data /// </summary> /// <param name = "parentNode">The parent node.</param> /// <param name = "data">The CData section value.</param> /// <returns>The created CData Section</returns> public static XmlCDataSection CreateCDataSection(this XmlNode parentNode, string data) { var document = (parentNode is XmlDocument ? (XmlDocument) parentNode : parentNode.OwnerDocument); var node = document.CreateCDataSection(data); parentNode.AppendChild(node); return node; }
public static XmlElement AppendChildElement(this XmlElement root, string name) { var elem = root.OwnerDocument.CreateElement(name); root.AppendChild(elem); return elem; }
public static XmlNode CreateChildNode(this XmlNode a_node, string a_name) { var document = (a_node is XmlDocument ? (XmlDocument)a_node : a_node.OwnerDocument); XmlNode node = document.CreateElement(a_name); a_node.AppendChild(node); return node; }
public static XmlNode AppendChildElement(this XmlNode node, string key) { XmlNode newNode = node.OwnerDocument.CreateElement(key); node.AppendChild(newNode); return newNode; }
public static void AppendChildren(this XmlElement element, IEnumerable<XmlElement> children) { foreach (var item in children) { element.AppendChild(item); } }
public static void AppendChildren(this HtmlNode node, IEnumerable<HtmlNode> newChildren) { foreach (var child in newChildren) { node.AppendChild(child); } }
public static XmlNode AppendElement(this XmlNode parent, string tagName, string textContent, bool checkTextContent = true) { if (!checkTextContent || !string.IsNullOrEmpty(textContent)) { XmlDocument xd; if (parent is XmlDocument) { xd = (XmlDocument)parent; } else { xd = parent.OwnerDocument; } XmlNode node = xd.CreateElement(tagName); parent.AppendChild(node); if (textContent != null) { XmlNode content = xd.CreateTextNode(textContent); node.AppendChild(content); } return node; } return null; }
public static XmlElement WithRoot(this XmlDocument document, string name) { XmlElement element = document.CreateElement(name); document.AppendChild(element); return element; }
/// <summary> /// Adds a new keyword xml node to a <see cref="T:System.Xml.XmlNode" /> /// </summary> /// <param name="node"><see cref="T:System.Xml.XmlNode" /></param> /// <param name="name">xml Node Name</param> /// <param name="value"><see cref="T:Tridion.ContentManager.ContentManagement.Keyword" /></param> /// <param name="includeLevel">if set to <c>true</c> [include level].</param> /// <returns> /// <see cref="T:System.Xml.XmlElement" /> keyword node /// </returns> public static XmlElement AddKeywordNode(this XmlNode node, String name, Keyword value, bool includeLevel) { if (node != null && !String.IsNullOrEmpty(name) && node.OwnerDocument != null && value != null) { XmlElement xElement = node.OwnerDocument.CreateElement(name); xElement.SetAttribute("uri", value.Id); if (!String.IsNullOrEmpty(value.Key)) xElement.SetAttribute("key", value.Key); if (!String.IsNullOrEmpty(value.Description)) xElement.SetAttribute("description", value.Description); xElement.SetAttribute("root", value.IsRoot.ToString().ToLower()); if (includeLevel) xElement.SetAttribute("level", value.Level().ToString()); xElement.InnerXml = SecurityElement.Escape(value.Title); node.AppendChild(xElement); return xElement; } return null; }
public static XmlElement AddElement(this XmlNode element, string name) { XmlElement child = element.OwnerDocument.CreateElement(name); element.AppendChild(child); return child; }
/// <summary> /// Creates an <see cref="XmlElement" /> and appends it as child to the XmlNode /// </summary> /// <param name="node"> The parent node </param> /// <param name="name"> Name of the newly created element </param> /// <returns> </returns> public static XmlElement AddElement(this XmlNode node, string name) { var doc = node as XmlDocument; doc = doc ?? node.OwnerDocument; XmlElement element = doc.CreateElement(name); node.AppendChild(element); return element; }
public static XmlElement AppendElement(this XmlDocument doc, string name, string innerText = null) { XmlElement newElement = doc.CreateElement(name); newElement.InnerText = innerText; doc.AppendChild(newElement); return newElement; }
public static XmlNode AddNodes(this XmlNode node, IEnumerable<XmlNode> nodes) { if (nodes != null && node != null) { nodes.ToList().ForEach(x => node.AppendChild(x)); } return node; }
/// <summary> /// Create a new XML Element /// </summary> /// <param name="parent">The parent node</param> /// <param name="name">The new element name</param> /// <param name="value">The new element value</param> /// <returns></returns> public static XmlElement NewElement(this XmlElement parent, string name, object value) { var e = parent.OwnerDocument.CreateElement(name); if (value != null) e.InnerText = value.ToString(); parent.AppendChild(e); return e; }
public static XmlNode AddChildNode(this XmlNode xmlNode, string name, string value) { XmlNode node = xmlNode.OwnerDocument.CreateElement(name); node.InnerText = value??string.Empty; xmlNode.AppendChild(node); return node; }
public static XmlElement AddElement(this XmlDocument document, string name) { var child = document.CreateElement(name); document.AppendChild(child); return child; }
public static XmlElement AppendElement(this XmlElement element, string name, string innerText = null) { XmlElement newElement = element.OwnerDocument.CreateElement(name); newElement.InnerText = innerText; element.AppendChild(newElement); return newElement; }
public static XmlElement Elem(this XmlNode node, string localName) { if (node == null) return null; var doc = node as XmlDocument; var newElem = (doc ?? node.OwnerDocument).CreateElement(localName); node.AppendChild(newElem); return newElem; }
/// <summary> /// Создать и добавить XML-элемент /// </summary> public static XmlElement AppendElem(this XmlElement parentXmlElem, string elemName, object innerText) { XmlElement xmlElem = parentXmlElem.OwnerDocument.CreateElement(elemName); string val = XmlValToStr(innerText); if (!string.IsNullOrEmpty(val)) xmlElem.InnerText = val; return (XmlElement)parentXmlElem.AppendChild(xmlElem); }