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
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
csprojPathstringThe path to the file to modify.
xmlNamespaceXNamespaceThe namespace to add or remove.
isAddingboolTrue to add the namespace, false to remove it.
Returns
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
contentstringThe XML content string.
xmlNamespaceXNamespaceThe namespace to add or remove.
isAddingboolTrue to add the namespace, false to remove it.
Returns
InnerXml(string)
Returns the inner XML of the document element parsed from the specified XML string.
public static string InnerXml(string xml)
Parameters
xmlstringThe XML string to parse.
Returns
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
xmlstringThe XML content string or file path.
Returns
RemoveXmlDeclaration(string)
Removes all forms of XML declaration from the input text.
public static string RemoveXmlDeclaration(string text)
Parameters
textstringThe text containing XML declarations to remove.
Returns
ReplaceAmpInString(string)
Replaces standalone ampersands (not part of valid XML entities) with the XML-safe & entity.
public static string ReplaceAmpInString(string xml)
Parameters
xmlstringThe XML string to process.
Returns
ReplaceSpecialHtmlEntity(string)
Replaces special HTML entity references (right/left single quotation marks) with their literal equivalents.
public static string ReplaceSpecialHtmlEntity(string text)
Parameters
textstringThe text containing HTML entities to replace.
Returns
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
xmlstringThe XML string to parse.
Returns
ReturnXmlRoot(string)
Parses the XML string and returns the root node (last child of the document).
public static XmlNode? ReturnXmlRoot(string xml)
Parameters
xmlstringThe XML string to parse.
Returns
SanitizeXmlString(string)
Removes illegal XML characters from a string, keeping only characters allowed by XML 1.0.
public static string SanitizeXmlString(string xml)
Parameters
xmlstringThe XML string to sanitize.