Table of Contents

Class StringExtensions

Namespace
Cuemon.Extensions.Xml
Assembly
Cuemon.Extensions.Xml.dll

Extension methods for the String class.

public static class StringExtensions
Inheritance
StringExtensions

Methods

EscapeXml(String)

Escapes the given XML value.

public static string EscapeXml(this string value)

Parameters

value String

The String to extend.

Returns

String

The input value with an escaped equivalent.

Exceptions

ArgumentNullException

value cannot be null.

SanitizeXmlElementName(String)

Sanitizes the value for any invalid characters.

public static string SanitizeXmlElementName(this string value)

Parameters

value String

The String to extend.

Returns

String

A sanitized String of value.

Remarks

Sanitation rules are as follows:

  1. Names can contain letters, numbers, and these 4 characters: _ | : | . | -
  2. Names cannot start with a number or punctuation character
  3. Names cannot contain spaces

Exceptions

ArgumentNullException

value cannot be null.

SanitizeXmlElementText(String, Boolean)

Sanitizes the value for any invalid characters.

public static string SanitizeXmlElementText(this string value, bool cdataSection = false)

Parameters

value String

The String to extend.

cdataSection Boolean

if set to true supplemental CDATA-section rules is applied to value.

Returns

String

A sanitized String of value.

Remarks

Sanitation rules are as follows:

  1. The value cannot contain characters less or equal to a Unicode value of U+0019 (except U+0009, U+0010, U+0013)
  2. The value cannot contain the string "]]<" if cdataSection is true.

UnescapeXml(String)

Unescapes the given XML value.

public static string UnescapeXml(this string value)

Parameters

value String

The String to extend.

Returns

String

The input value with an unescaped equivalent.

Exceptions

ArgumentNullException

value cannot be null.