Table of Contents

Class XH

Namespace
SunamoXml
Assembly
SunamoXml.dll

XML helper class operating on XmlDocument and XDocument for loading, sanitizing, and manipulating XML content.

public class XH
Inheritance
XH
Inherited Members
Extension Methods

Properties

XmlDocument

Shared XmlDocument instance for general-purpose XML operations.

public static XmlDocument XmlDocument { get; set; }

Property Value

XmlDocument

Methods

AddXmlns(string, XNamespace, bool)

Adds or removes an XML namespace from a .csproj or XML file.

public static Task AddXmlns(string csprojPath, XNamespace xmlNamespace, bool isAdding)

Parameters

csprojPath string

The path to the file to modify.

xmlNamespace XNamespace

The namespace to add or remove.

isAdding bool

True to add the namespace, false to remove it.

Returns

Task

AddXmlnsContent(string, XNamespace, bool)

Adds or removes an XML namespace from an in-memory XML string.

public static string AddXmlnsContent(string content, XNamespace xmlNamespace, bool isAdding)

Parameters

content string

The XML content string.

xmlNamespace XNamespace

The namespace to add or remove.

isAdding bool

True to add the namespace, false to remove it.

Returns

string

InnerXml(string)

Returns the inner XML of the document element parsed from the specified XML string.

public static string InnerXml(string xml)

Parameters

xml string

The XML string to parse.

Returns

string

LoadXml(string)

Loads XML from a string or file path and returns the parsed XmlDocument. Returns null on parse failure.

public static Task<XmlDocument?> LoadXml(string xml)

Parameters

xml string

The XML content string or file path.

Returns

Task<XmlDocument>

RemoveXmlDeclaration(string)

Removes all forms of XML declaration from the input text.

public static string RemoveXmlDeclaration(string text)

Parameters

text string

The text containing XML declarations to remove.

Returns

string

ReplaceAmpInString(string)

Replaces standalone ampersands (not part of valid XML entities) with the XML-safe &amp; entity.

public static string ReplaceAmpInString(string xml)

Parameters

xml string

The XML string to process.

Returns

string

ReplaceSpecialHtmlEntity(string)

Replaces special HTML entity references (right/left single quotation marks) with their literal equivalents.

public static string ReplaceSpecialHtmlEntity(string text)

Parameters

text string

The text containing HTML entities to replace.

Returns

string

ReturnXmlNode(string)

Parses the XML string preserving whitespace and returns the first child node (typically the XML declaration).

public static XmlNode? ReturnXmlNode(string xml)

Parameters

xml string

The XML string to parse.

Returns

XmlNode

ReturnXmlRoot(string)

Parses the XML string and returns the root node (last child of the document).

public static XmlNode? ReturnXmlRoot(string xml)

Parameters

xml string

The XML string to parse.

Returns

XmlNode

SanitizeXmlString(string)

Removes illegal XML characters from a string, keeping only characters allowed by XML 1.0.

public static string SanitizeXmlString(string xml)

Parameters

xml string

The XML string to sanitize.

Returns

string