Table of Contents

Class XObjectUtility

Namespace
Songhay.Xml
Assembly
SonghayCore.dll

Static helper members for XML-related routines.

public static class XObjectUtility
Inheritance
XObjectUtility
Inherited Members

Remarks

These definitions are biased toward emitting XPathDocument documents. However, many accept any input implementing the IXPathNavigable interface.

Fields

GlyphNonBreakingSpace

Glyph: Non-Breaking Space

public const string GlyphNonBreakingSpace = " "

Field Value

string

Properties

XTextNonBreakingSpace

XText: Non-Breaking Space

public static XText XTextNonBreakingSpace { get; }

Property Value

XText

Methods

GetCDataValue(XElement?)

Get the CDATA value from the specified XElement.

public static string? GetCDataValue(XElement? element)

Parameters

element XElement

The XElement.

Returns

string

GetCDataValue(XNode?)

Get the CDATA value from the specified XNode.

public static string? GetCDataValue(XNode? node)

Parameters

node XNode

The XNode.

Returns

string

GetLocalNameXPathQuery(string?)

Gets the XNode into a local-name(), XPath-predicate query.

public static string? GetLocalNameXPathQuery(string? childElementName)

Parameters

childElementName string

Name of the child element.

Returns

string

GetLocalNameXPathQuery(string?, string?)

Gets the XNode into a local-name(), XPath-predicate query.

public static string? GetLocalNameXPathQuery(string? namespacePrefixOrUri, string? childElementName)

Parameters

namespacePrefixOrUri string

The namespace prefix or URI.

childElementName string

Name of the child element.

Returns

string

GetLocalNameXPathQuery(string?, string?, string?)

Gets the XNode into a local-name(), XPath-predicate query.

public static string? GetLocalNameXPathQuery(string? namespacePrefixOrUri, string? childElementName, string? childAttributeName)

Parameters

namespacePrefixOrUri string

The namespace prefix or URI.

childElementName string

Name of the child element.

childAttributeName string

Name of the child attribute.

Returns

string

Remarks

This routine is useful when namespace-resolving is not desirable or available.

GetValue(XNode?, string?)

Gets the element or attribute value of the specified element.

public static string? GetValue(XNode? currentNode, string? query)

Parameters

currentNode XNode

The current element.

query string

The xpath query.

Returns

string

GetValue(XNode?, string?, bool)

Gets the element or attribute value of the current element.

public static string? GetValue(XNode? currentNode, string? query, bool throwException)

Parameters

currentNode XNode

The current XNode.

query string

The xpath query.

throwException bool

if set to true throw exception.

Returns

string

GetXAttributeValue(XNode?, string?, bool)

Returns an object for parsing and adding to a list of parameters for data access.

public static string? GetXAttributeValue(XNode? node, string? nodeQuery, bool throwException)

Parameters

node XNode

The XNode.

nodeQuery string

The node query string.

throwException bool

When

true

, throw an exception for null nodes.

Returns

string

GetXAttributeValue(XNode?, string?, bool, string?)

Returns an object for parsing and adding to a list of parameters for data access.

public static string? GetXAttributeValue(XNode? node, string? nodeQuery, bool throwException, string? defaultValue)

Parameters

node XNode

The XNode.

nodeQuery string

The node query string.

throwException bool

When

true

, throw an exception for null nodes.

defaultValue string

Return the specified default value for “zero-length” text nodes.

Returns

string

GetXAttributeValue(XNode?, string?, bool, string?, IXmlNamespaceResolver?)

Returns an object for parsing and adding to a list of parameters for data access.

public static string? GetXAttributeValue(XNode? node, string? nodeQuery, bool throwException, string? defaultValue, IXmlNamespaceResolver? resolver)

Parameters

node XNode

The XNode.

nodeQuery string

The node query string.

throwException bool

When

true

, throw an exception for null nodes.

defaultValue string

Return the specified default value for “zero-length” text nodes.

resolver IXmlNamespaceResolver

The IXmlNamespaceResolver to use to resolve prefixes.

Returns

string

GetXAttributeValueAndParse<T>(XNode?, string?, bool, T)

Returns an object for parsing and adding to a list of parameters for data access.

public static object? GetXAttributeValueAndParse<T>(XNode? node, string? nodeQuery, bool throwException, T defaultValue)

Parameters

node XNode

The XNode.

nodeQuery string

The XPath string.

throwException bool
When 
true

, throw an exception for null nodes and nodes that do not parse into the specified type.

defaultValue T

Return a boxing object for “zero-length” text nodes.

Returns

object

Type Parameters

T

The type to parse from the node value.

GetXAttributeValueAndParse<T>(XNode?, string?, bool, T?, IXmlNamespaceResolver?)

Returns an object for parsing and adding to a list of parameters for data access.

public static object? GetXAttributeValueAndParse<T>(XNode? node, string? nodeQuery, bool throwException, T? defaultValue, IXmlNamespaceResolver? resolver)

Parameters

node XNode

The XNode.

nodeQuery string

The XPath string.

throwException bool
When 
true

, throw an exception for null nodes and nodes that do not parse into the specified type.

defaultValue T

Return a boxing object for “zero-length” text nodes.

resolver IXmlNamespaceResolver

The IXmlNamespaceResolver to use to resolve prefixes.

Returns

object

Type Parameters

T

The type to parse from the node value.

GetXDeclaration()

Gets the XDeclaration.

public static XDeclaration GetXDeclaration()

Returns

XDeclaration

GetXDeclaration(string?, bool)

Gets the XDeclaration.

public static XDeclaration GetXDeclaration(string? encoding, bool isStandAlone)

Parameters

encoding string

The encoding (Utf08 by default).

isStandAlone bool

When true document is stand-alone (true by default).

Returns

XDeclaration

GetXElement(string?, object?)

Gets the XElement.

public static XElement GetXElement(string? rootElement, object? innerXml)

Parameters

rootElement string

The root element name.

innerXml object

The inner XML.

Returns

XElement

GetXElement(XNode?, string?)

Gets the XElement.

public static XElement? GetXElement(XNode? root, string? pathToElement)

Parameters

root XNode

The root XNode.

pathToElement string

The XPath to element.

Returns

XElement

GetXElements(XNode?, string?)

Gets the IEnumerable<T>.

public static IEnumerable<XElement> GetXElements(XNode? currentElement, string? query)

Parameters

currentElement XNode

The current element.

query string

The xpath query.

Returns

IEnumerable<XElement>

GetXNode(XNode?, string?)

Gets the XNode from the specified XPath query.

public static XNode? GetXNode(XNode? node, string? nodeQuery)

Parameters

node XNode

The node.

nodeQuery string

The node query.

Returns

XNode

GetXNode(XNode?, string?, bool)

Gets the XNode from the specified XPath query.

public static XNode? GetXNode(XNode? node, string? nodeQuery, bool throwException)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

Returns

XNode

GetXNode(XNode?, string?, bool, IXmlNamespaceResolver)

Gets the XNode from the specified XPath query.

public static XNode? GetXNode(XNode? node, string? nodeQuery, bool throwException, IXmlNamespaceResolver resolver)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

resolver IXmlNamespaceResolver

The resolver.

Returns

XNode

GetXNodes(XNode?, string?)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XNode> GetXNodes(XNode? node, string? nodeQuery)

Parameters

node XNode

The node.

nodeQuery string

The node query.

Returns

IEnumerable<XNode>

GetXNodes(XNode?, string?, bool)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XNode> GetXNodes(XNode? node, string? nodeQuery, bool throwException)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

Returns

IEnumerable<XNode>

GetXNodes(XNode?, string?, bool, IXmlNamespaceResolver?)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XNode> GetXNodes(XNode? node, string? nodeQuery, bool throwException, IXmlNamespaceResolver? resolver)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

resolver IXmlNamespaceResolver

The resolver.

Returns

IEnumerable<XNode>

GetXObject(XNode?, string?)

Gets the XObject from the specified XPath query.

public static XObject? GetXObject(XNode? node, string? nodeQuery)

Parameters

node XNode

The XNode node.

nodeQuery string

The node query string.

Returns

XObject

GetXObject(XNode?, string?, bool)

Gets the XObject from the specified XPath query.

public static XObject? GetXObject(XNode? node, string? nodeQuery, bool throwException)

Parameters

node XNode

The XNode node.

nodeQuery string

The node query string.

throwException bool

When

true

, throw an exception for null nodes.

Returns

XObject

GetXObject(XNode?, string?, bool, IXmlNamespaceResolver?)

Gets the XObject.

public static XObject? GetXObject(XNode? node, string? nodeQuery, bool throwException, IXmlNamespaceResolver? resolver)

Parameters

node XNode

The XNode node.

nodeQuery string

The node query string.

throwException bool

When

true

, throw an exception for null nodes.

resolver IXmlNamespaceResolver

The IXmlNamespaceResolver to use to resolve prefixes.

Returns

XObject

GetXObjects(XNode?, string?)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XObject> GetXObjects(XNode? node, string? nodeQuery)

Parameters

node XNode

The node.

nodeQuery string

The node query.

Returns

IEnumerable<XObject>

GetXObjects(XNode?, string?, bool)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XObject> GetXObjects(XNode? node, string? nodeQuery, bool throwException)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

Returns

IEnumerable<XObject>

GetXObjects(XNode?, string?, bool, IXmlNamespaceResolver?)

Gets IEnumerable<T> from the specified XPath query.

public static IEnumerable<XObject> GetXObjects(XNode? node, string? nodeQuery, bool throwException, IXmlNamespaceResolver? resolver)

Parameters

node XNode

The node.

nodeQuery string

The node query.

throwException bool

When

true

, throw an exception for null nodes.

resolver IXmlNamespaceResolver

The resolver.

Returns

IEnumerable<XObject>

JoinFlattenedXTextNodes(XElement?)

Joins the flattened XText nodes.

public static string? JoinFlattenedXTextNodes(XElement? rootElement)

Parameters

rootElement XElement

The root element.

Returns

string

JoinFlattenedXTextNodes(XElement?, bool)

Joins the flattened XText nodes.

public static string? JoinFlattenedXTextNodes(XElement? rootElement, bool includeRootElement)

Parameters

rootElement XElement

The root element.

includeRootElement bool

When true include root element.

Returns

string

JoinFlattenedXTextNodes(XElement?, bool, string?)

Joins the flattened XText nodes.

public static string? JoinFlattenedXTextNodes(XElement? rootElement, bool includeRootElement, string? joinDelimiter)

Parameters

rootElement XElement

The root element.

includeRootElement bool

When true include root element.

joinDelimiter string

The join delimiter.

Returns

string