Class XmlExtensions
Extension methods for xml objects
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class XmlExtensions
Methods
View SourceAttributeValue<T>(XElement, String)
Declaration
public static T AttributeValue<T>(this XElement xml, string attributeName)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XElement | xml | |
System.String | attributeName |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
AttributeValue<T>(XmlNode, String)
Declaration
public static T AttributeValue<T>(this XmlNode xml, string attributeName)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | xml | |
System.String | attributeName |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
GetXElement(XmlNode)
Declaration
public static XElement GetXElement(this XmlNode node)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | node |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement |
GetXmlNode(XContainer)
Declaration
public static XmlNode GetXmlNode(this XContainer element)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XContainer | element |
Returns
Type | Description |
---|---|
System.Xml.XmlNode |
GetXmlNode(XContainer, XmlDocument)
Declaration
public static XmlNode GetXmlNode(this XContainer element, XmlDocument xmlDoc)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XContainer | element | |
System.Xml.XmlDocument | xmlDoc |
Returns
Type | Description |
---|---|
System.Xml.XmlNode |
HasAttribute(XmlAttributeCollection, String)
Declaration
public static bool HasAttribute(this XmlAttributeCollection attributes, string attributeName)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlAttributeCollection | attributes | |
System.String | attributeName |
Returns
Type | Description |
---|---|
System.Boolean |
RequiredAttributeValue<T>(XElement, String)
Declaration
public static T RequiredAttributeValue<T>(this XElement xml, string attributeName)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XElement | xml | |
System.String | attributeName |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
SelectNodes(XmlNode, String, Nullable<IEnumerable<XPathVariable>>)
Selects a list of XmlNode matching an XPath expression.
Declaration
public static XmlNodeList SelectNodes(this XmlNode source, string expression, IEnumerable<XPathVariable>? variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.String | expression | An XPath expression. |
System.Nullable<IEnumerable<XPathVariable>> | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNodeList | The list of XmlNode matching the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectNodes(XmlNode, String, XPathVariable[])
Selects a list of XmlNode matching an XPath expression.
Declaration
public static XmlNodeList SelectNodes(this XmlNode source, string expression, params XPathVariable[] variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.String | expression | An XPath expression. |
XPathVariable[] | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNodeList | The list of XmlNode matching the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectNodes(XmlNode, XPathExpression, Nullable<IEnumerable<XPathVariable>>)
Selects a list of XmlNode matching an XPath expression.
Declaration
public static XmlNodeList SelectNodes(this XmlNode source, XPathExpression expression, IEnumerable<XPathVariable>? variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.Xml.XPath.XPathExpression | expression | An XPath expression. |
System.Nullable<IEnumerable<XPathVariable>> | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNodeList | The list of XmlNode matching the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectNodes(XmlNode, XPathExpression, XPathVariable[])
Selects a list of XmlNode matching an XPath expression.
Declaration
public static XmlNodeList SelectNodes(this XmlNode source, XPathExpression expression, params XPathVariable[] variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.Xml.XPath.XPathExpression | expression | An XPath expression. |
XPathVariable[] | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNodeList | The list of XmlNode matching the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectSingleNode(XmlNode, String, Nullable<IEnumerable<XPathVariable>>)
Selects the first XmlNode that matches an XPath expression.
Declaration
public static XmlNode SelectSingleNode(this XmlNode source, string expression, IEnumerable<XPathVariable>? variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.String | expression | An XPath expression. |
System.Nullable<IEnumerable<XPathVariable>> | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNode | The first XmlNode that matches the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectSingleNode(XmlNode, String, XPathVariable[])
Selects the first XmlNode that matches an XPath expression.
Declaration
public static XmlNode SelectSingleNode(this XmlNode source, string expression, params XPathVariable[] variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.String | expression | An XPath expression. |
XPathVariable[] | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNode | The first XmlNode that matches the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectSingleNode(XmlNode, XPathExpression, Nullable<IEnumerable<XPathVariable>>)
Selects the first XmlNode that matches an XPath expression.
Declaration
public static XmlNode SelectSingleNode(this XmlNode source, XPathExpression expression, IEnumerable<XPathVariable>? variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.Xml.XPath.XPathExpression | expression | An XPath expression. |
System.Nullable<IEnumerable<XPathVariable>> | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNode | The first XmlNode that matches the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
SelectSingleNode(XmlNode, XPathExpression, XPathVariable[])
Selects the first XmlNode that matches an XPath expression.
Declaration
public static XmlNode SelectSingleNode(this XmlNode source, XPathExpression expression, params XPathVariable[] variables)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | source | A source XmlNode. |
System.Xml.XPath.XPathExpression | expression | An XPath expression. |
XPathVariable[] | variables | A set of XPathVariables. |
Returns
Type | Description |
---|---|
System.Xml.XmlNode | The first XmlNode that matches the XPath expression. |
Remarks
If
is null
, or is empty, or contains only one single
value which itself is null
, then variables are ignored.
The XPath expression should reference variables as $var
.
ToDataString(XElement)
Declaration
public static string ToDataString(this XElement xml)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XElement | xml |
Returns
Type | Description |
---|---|
System.String |
ToXDocument(XmlDocument)
Converts from an XmlDocument to an XDocument
Declaration
public static XDocument ToXDocument(this XmlDocument xmlDocument)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlDocument | xmlDocument |
Returns
Type | Description |
---|---|
System.Xml.Linq.XDocument |
ToXElement(XmlNode)
Converts from an XmlElement to an XElement
Declaration
public static XElement ToXElement(this XmlNode xmlElement)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | xmlElement |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement |
ToXmlDocument(XDocument)
Converts from an XDocument to an XmlDocument
Declaration
public static XmlDocument ToXmlDocument(this XDocument xDocument)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XDocument | xDocument |
Returns
Type | Description |
---|---|
System.Xml.XmlDocument |
ToXmlElement(XContainer)
Declaration
public static XmlNode ToXmlElement(this XContainer xElement)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.Linq.XContainer | xElement |
Returns
Type | Description |
---|---|
System.Xml.XmlNode |