Search Results for

    Show / Hide Table of Contents
    View Source

    Class XmlHelper

    The XmlHelper class contains general helper methods for working with xml in umbraco.

    Inheritance
    System.Object
    Namespace: Umbraco.Cms.Core.Xml
    Assembly: Umbraco.Core.dll
    Syntax
    public class XmlHelper

    Methods

    View Source

    AddAttribute(XmlDocument, String, String)

    creates a XmlAttribute with the specified name and value

    Declaration
    public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.String name

    The name of the attribute.

    System.String value

    The value of the attribute.

    Returns
    Type Description
    System.Xml.XmlAttribute

    a XmlAttribute

    View Source

    AddCDataNode(XmlDocument, String, String)

    Creates a cdata XmlNode with the specified name and value

    Declaration
    public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.String name

    The node name.

    System.String value

    The node value.

    Returns
    Type Description
    System.Xml.XmlNode

    A XmlNode

    View Source

    AddTextNode(XmlDocument, String, String)

    Creates a text XmlNode with the specified name and value

    Declaration
    public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.String name

    The node name.

    System.String value

    The node value.

    Returns
    Type Description
    System.Xml.XmlNode

    a XmlNode

    View Source

    CouldItBeXml(String)

    Determines whether the specified string appears to be XML.

    Declaration
    public static bool CouldItBeXml(string xml)
    Parameters
    Type Name Description
    System.String xml

    The XML string.

    Returns
    Type Description
    System.Boolean

    true if the specified string appears to be XML; otherwise, false.

    View Source

    CreateXPathDocument(String)

    Creates a new XPathDocument from an xml string.

    Declaration
    public static XPathDocument CreateXPathDocument(string xml)
    Parameters
    Type Name Description
    System.String xml

    The xml string.

    Returns
    Type Description
    System.Xml.XPath.XPathDocument

    An XPathDocument created from the xml string.

    View Source

    GetAttributesFromElement(String)

    Return a dictionary of attributes found for a string based tag

    Declaration
    public static Dictionary<string, string> GetAttributesFromElement(string tag)
    Parameters
    Type Name Description
    System.String tag
    Returns
    Type Description
    Umbraco.Cms.Core.Dictionary<System.String, System.String>
    View Source

    GetNodeValue(XmlNode)

    Gets the value of a XmlNode

    Declaration
    public static string GetNodeValue(XmlNode n)
    Parameters
    Type Name Description
    System.Xml.XmlNode n

    The XmlNode.

    Returns
    Type Description
    System.String

    the value as a string

    View Source

    IsXmlWhitespace(String)

    Gets a value indicating whether a specified string contains only xml whitespace characters.

    Declaration
    public static bool IsXmlWhitespace(string s)
    Parameters
    Type Name Description
    System.String s

    The string.

    Returns
    Type Description
    System.Boolean

    true if the string contains only xml whitespace characters.

    Remarks

    As per XML 1.1 specs, space, \t, \r and \n.

    View Source

    OpenAsXmlDocument(String, IHostingEnvironment)

    Opens a file as a XmlDocument.

    Declaration
    public static XmlDocument OpenAsXmlDocument(string filePath, IHostingEnvironment hostingEnvironment)
    Parameters
    Type Name Description
    System.String filePath

    The relative file path. ie. /config/umbraco.config

    IHostingEnvironment hostingEnvironment
    Returns
    Type Description
    System.Xml.XmlDocument

    Returns a XmlDocument class

    View Source

    SetAttribute(XmlDocument, XmlNode, String, String)

    Creates or sets an attribute on the XmlNode if an Attributes collection is available

    Declaration
    public static void SetAttribute(XmlDocument xml, XmlNode n, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xml
    System.Xml.XmlNode n
    System.String name
    System.String value
    View Source

    SetCDataNode(XmlDocument, XmlNode, String, String)

    Sets or Creates a cdata XmlNode with the specified name and value

    Declaration
    public static XmlNode SetCDataNode(XmlDocument xd, XmlNode parent, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.Xml.XmlNode parent

    The node to set or create the child text node on

    System.String name

    The node name.

    System.String value

    The node value.

    Returns
    Type Description
    System.Xml.XmlNode

    a XmlNode

    View Source

    SetInnerXmlNode(XmlDocument, XmlNode, String, String)

    Sets or creates an Xml node from its inner Xml.

    Declaration
    public static XmlNode SetInnerXmlNode(XmlDocument xd, XmlNode parent, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.Xml.XmlNode parent

    The node to set or create the child text node on

    System.String name

    The node name.

    System.String value

    The node inner Xml.

    Returns
    Type Description
    System.Xml.XmlNode

    a XmlNode

    View Source

    SetTextNode(XmlDocument, XmlNode, String, String)

    Sets or Creates a text XmlNode with the specified name and value

    Declaration
    public static XmlNode SetTextNode(XmlDocument xd, XmlNode parent, string name, string value)
    Parameters
    Type Name Description
    System.Xml.XmlDocument xd

    The xmldocument.

    System.Xml.XmlNode parent

    The node to set or create the child text node on

    System.String name

    The node name.

    System.String value

    The node value.

    Returns
    Type Description
    System.Xml.XmlNode

    a XmlNode

    View Source

    SortNode(XmlNode, String, XmlNode, Func<XmlNode, Int32>)

    Sorts a single child node of a parentNode.

    Declaration
    public static bool SortNode(XmlNode parentNode, string childNodesXPath, XmlNode node, Func<XmlNode, int> orderBy)
    Parameters
    Type Name Description
    System.Xml.XmlNode parentNode

    The parent node.

    System.String childNodesXPath

    An XPath expression to select children of parentNode to sort.

    System.Xml.XmlNode node

    The child node to sort.

    Func<System.Xml.XmlNode, System.Int32> orderBy

    A function returning the value to order the nodes by.

    Returns
    Type Description
    System.Boolean

    A value indicating whether sorting was needed.

    Remarks

    Assuming all nodes but node are sorted, this will move the node to the right position without moving all the nodes (as SortNodes would do) - should improve perfs.

    View Source

    SortNodes(XmlNode, String, Func<XmlNode, Int32>)

    Sorts the children of a parentNode.

    Declaration
    public static void SortNodes(XmlNode parentNode, string childNodesXPath, Func<XmlNode, int> orderBy)
    Parameters
    Type Name Description
    System.Xml.XmlNode parentNode

    The parent node.

    System.String childNodesXPath

    An XPath expression to select children of parentNode to sort.

    Func<System.Xml.XmlNode, System.Int32> orderBy

    A function returning the value to order the nodes by.

    View Source

    TryCreateXPathDocument(String, out XPathDocument)

    Tries to create a new XPathDocument from an xml string.

    Declaration
    public static bool TryCreateXPathDocument(string xml, out XPathDocument doc)
    Parameters
    Type Name Description
    System.String xml

    The xml string.

    System.Xml.XPath.XPathDocument doc

    The XPath document.

    Returns
    Type Description
    System.Boolean

    A value indicating whether it has been possible to create the document.

    View Source

    TryCreateXPathDocumentFromPropertyValue(Object, out XPathDocument)

    Tries to create a new XPathDocument from a property value.

    Declaration
    public static bool TryCreateXPathDocumentFromPropertyValue(object value, out XPathDocument doc)
    Parameters
    Type Name Description
    System.Object value

    The value of the property.

    System.Xml.XPath.XPathDocument doc

    The XPath document.

    Returns
    Type Description
    System.Boolean

    A value indicating whether it has been possible to create the document.

    Remarks

    The value can be anything... Performance-wise, this is bad.

    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • AddAttribute(XmlDocument, String, String)
      • AddCDataNode(XmlDocument, String, String)
      • AddTextNode(XmlDocument, String, String)
      • CouldItBeXml(String)
      • CreateXPathDocument(String)
      • GetAttributesFromElement(String)
      • GetNodeValue(XmlNode)
      • IsXmlWhitespace(String)
      • OpenAsXmlDocument(String, IHostingEnvironment)
      • SetAttribute(XmlDocument, XmlNode, String, String)
      • SetCDataNode(XmlDocument, XmlNode, String, String)
      • SetInnerXmlNode(XmlDocument, XmlNode, String, String)
      • SetTextNode(XmlDocument, XmlNode, String, String)
      • SortNode(XmlNode, String, XmlNode, Func<XmlNode, Int32>)
      • SortNodes(XmlNode, String, Func<XmlNode, Int32>)
      • TryCreateXPathDocument(String, out XPathDocument)
      • TryCreateXPathDocumentFromPropertyValue(Object, out XPathDocument)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX