Class XmlHelper
The XmlHelper class contains general helper methods for working with xml in umbraco.
Inheritance
Namespace: Umbraco.Core.Xml
Assembly: Umbraco.Core.dll
Syntax
public class XmlHelper
Methods
View SourceAddAttribute(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 |
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 |
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 |
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 |
|
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 |
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 |
|
Remarks
As per XML 1.1 specs, space, \t, \r and \n.
OpenAsXmlDocument(String)
Opens a file as a XmlDocument.
Declaration
public static XmlDocument OpenAsXmlDocument(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The relative file path. ie. /config/umbraco.config |
Returns
Type | Description |
---|---|
System.Xml.XmlDocument | Returns a XmlDocument class |
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 |
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 |
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 |
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 |
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. |
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.