Class SyndicationEncodingUtility
Provides methods for encoding and decoding information exposed by syndicated content. This class cannot be inherited.
Inheritance
Inherited Members
Namespace: Argotic.Common
Assembly: Argotic.Common.dll
Syntax
public static class SyndicationEncodingUtility
Methods
| Improve this Doc View SourceCreateSafeNavigator(Stream)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.IO.Stream.
Declaration
public static XPathNavigator CreateSafeNavigator(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The System.IO.Stream object that contains the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Remarks
The character encoding of the supplied stream
is automatically determined based on the encoding attribute of the XML document declaration.
If the character encoding cannot be determined, a default encoding of System.Text.Encoding.UTF8 is used.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateSafeNavigator(Stream, Encoding)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.IO.Stream using the specified System.Text.Encoding.
Declaration
public static XPathNavigator CreateSafeNavigator(Stream stream, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The System.IO.Stream object that contains the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
System.Text.Encoding | encoding | A System.Text.Encoding object that indicates the character encoding to use when reading the supplied |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
CreateSafeNavigator(TextReader)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.IO.TextReader.
Declaration
public static XPathNavigator CreateSafeNavigator(TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.IO.TextReader | reader | The System.IO.TextReader object that contains the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateSafeNavigator(String)
Creates a System.Xml.XPath.XPathNavigator against the supplied XML data.
Declaration
public static XPathNavigator CreateSafeNavigator(string xml)
Parameters
Type | Name | Description |
---|---|---|
System.String | xml | The XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied XML data.
The supplied |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
CreateSafeNavigator(Uri, WebRequestOptions)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
WebRequestOptions | options | A WebRequestOptions that holds options that should be applied to web requests. |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateSafeNavigator(Uri, WebRequestOptions, Encoding)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
WebRequestOptions | options | A WebRequestOptions that holds options that should be applied to web requests. |
System.Text.Encoding | encoding | A System.Text.Encoding object that indicates the expected character encoding of the supplied |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Remarks
If the encoding
is null, the character encoding of the supplied source
is determined automatically.
Otherwise the specified encoding
is used when reading the XML data represented by the supplied source
.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateSafeNavigator(Uri, ICredentials, IWebProxy)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static XPathNavigator CreateSafeNavigator(Uri source, ICredentials credentials, IWebProxy proxy)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
System.Net.ICredentials | credentials | A System.Net.ICredentials that provides the proper set of credentials to the |
System.Net.IWebProxy | proxy | A System.Net.IWebProxy that provides proxy access to the |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateSafeNavigator(Uri, ICredentials, IWebProxy, Encoding)
Creates a System.Xml.XPath.XPathNavigator against the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static XPathNavigator CreateSafeNavigator(Uri source, ICredentials credentials, IWebProxy proxy, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the XML data to be navigated by the created System.Xml.XPath.XPathNavigator. |
System.Net.ICredentials | credentials | A System.Net.ICredentials that provides the proper set of credentials to the |
System.Net.IWebProxy | proxy | A System.Net.IWebProxy that provides proxy access to the |
System.Text.Encoding | encoding | A System.Text.Encoding object that indicates the expected character encoding of the supplied |
Returns
Type | Description |
---|---|
System.Xml.XPath.XPathNavigator | An System.Xml.XPath.XPathNavigator that provides a cursor model for navigating the supplied |
Remarks
If the encoding
is null, the character encoding of the supplied source
is determined automatically.
Otherwise the specified encoding
is used when reading the XML data represented by the supplied source
.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateWebRequest(Uri, WebRequestOptions)
Returns a System.Net.WebRequest that makes a request for a resource located at the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static WebRequest CreateWebRequest(Uri source, WebRequestOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the resource to be retrieved. |
WebRequestOptions | options | A WebRequestOptions that holds options that should be applied to web requests. |
Returns
Type | Description |
---|---|
System.Net.WebRequest | An System.Net.WebRequest that makes a request to the |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateWebRequest(Uri, ICredentials, IWebProxy)
Returns a System.Net.WebRequest that makes a request for a resource located at the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static WebRequest CreateWebRequest(Uri source, ICredentials credentials, IWebProxy proxy)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the resource to be retrieved. |
System.Net.ICredentials | credentials | A System.Net.ICredentials that provides the proper set of credentials to the |
System.Net.IWebProxy | proxy | A System.Net.IWebProxy that provides proxy access to the |
Returns
Type | Description |
---|---|
System.Net.WebRequest | An System.Net.WebRequest that makes a request to the |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateWebResponse(Uri, WebRequestOptions)
Returns the System.Net.WebResponse to a request for a resource located at the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static WebResponse CreateWebResponse(Uri source, WebRequestOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the resource to be retrieved. |
WebRequestOptions | options | A WebRequestOptions that holds options that should be applied to web requests. |
Returns
Type | Description |
---|---|
System.Net.WebResponse | An System.Net.WebResponse that contains the response from the requested resource. If unable to create a System.Net.WebResponse for
the requested |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
CreateWebResponse(Uri, ICredentials, IWebProxy)
Returns the System.Net.WebResponse to a request for a resource located at the supplied System.Uri using the specified System.Net.ICredentials and System.Net.IWebProxy.
Declaration
public static WebResponse CreateWebResponse(Uri source, ICredentials credentials, IWebProxy proxy)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | source | A System.Uri that points to the location of the resource to be retrieved. |
System.Net.ICredentials | credentials | A System.Net.ICredentials that provides the proper set of credentials to the |
System.Net.IWebProxy | proxy | A System.Net.IWebProxy that provides proxy access to the |
Returns
Type | Description |
---|---|
System.Net.WebResponse | An System.Net.WebResponse that contains the response from the requested resource. If unable to create a System.Net.WebResponse for
the requested |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
DecodeBase64String(String)
Decodes a base64 encoded string.
Declaration
public static Stream DecodeBase64String(string encodedValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedValue | The base64 encoded string to decode. |
Returns
Type | Description |
---|---|
System.IO.Stream | A System.IO.Stream the represents the decoded result of the base64 encoded value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
DecodeHtmlEscapedString(String)
Decodes an HTML escaped string.
Declaration
public static string DecodeHtmlEscapedString(string escapedValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | escapedValue | The HTML escaped string to decode. |
Returns
Type | Description |
---|---|
System.String | A string the represents the unescaped result of the HTML escaped value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
EncodeInvalidXmlHexadecimalCharacters(String)
Encodes the supplied string so that it can be safely represented in XML.
Declaration
public static string EncodeInvalidXmlHexadecimalCharacters(string content)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that represents the XML data to parse for invalid XML hexadecimal characters. |
Returns
Type | Description |
---|---|
System.String | A string that has been encoded to be safe for XML. |
Remarks
The encoding process replaces invalid XML hexadecimal characters with their equivalent decimal representation.
Hexadecimal characters that are valid include: #x9, #xA, #xD, [#x20-#xD7FF], [#xE000-#xFFFD], [#x10000-#x10FFFF], and any Unicode character; excluding the surrogate blocks FFFE and FFFF.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
EncodeSafeDirectoryName(String)
Converts a string into a value that can be safely used as a System.IO.Directory name.
Declaration
public static string EncodeSafeDirectoryName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The directory name to encode. |
Returns
Type | Description |
---|---|
System.String | A string that can be safely used as an argument when System.IO.Directory.CreateDirectory(System.String). |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
GetXmlEncoding(Byte[])
Returns an System.Text.Encoding that represents the XML character encoding for the supplied array of bytes.
Declaration
public static Encoding GetXmlEncoding(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | An array of bytes that represents an XML data source to determine the character encoding for. |
Returns
Type | Description |
---|---|
System.Text.Encoding | A System.Text.Encoding that represents the character encoding specified by the XML data source. If the character encoding is not specified or unable to be determined, returns System.Text.Encoding.UTF8. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
GetXmlEncoding(Stream)
Returns an System.Text.Encoding that represents the XML character encoding for the supplied System.IO.Stream.
Declaration
public static Encoding GetXmlEncoding(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | A System.IO.Stream that represents an XML data source to determine the character encoding for. |
Returns
Type | Description |
---|---|
System.Text.Encoding | A System.Text.Encoding that represents the character encoding specified by the XML data source. If the character encoding is not specified or unable to be determined, returns System.Text.Encoding.UTF8. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
GetXmlEncoding(String)
Returns an System.Text.Encoding that represents the XML character encoding for the supplied content.
Declaration
public static Encoding GetXmlEncoding(string content)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that represents the XML data to determine the character encoding for. |
Returns
Type | Description |
---|---|
System.Text.Encoding | A System.Text.Encoding that represents the character encoding specified by the XML data. If the character encoding is not specified or unable to be determined, returns System.Text.Encoding.UTF8. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |
RemoveInvalidXmlHexadecimalCharacters(String)
Sanitizes the supplied string so that it can be safely represented in XML.
Declaration
public static string RemoveInvalidXmlHexadecimalCharacters(string content)
Parameters
Type | Name | Description |
---|---|---|
System.String | content | A string that represents the XML data to parse for invalid XML hexadecimal characters. |
Returns
Type | Description |
---|---|
System.String | A string that has been sanitized to be safe for XML. |
Remarks
The sanitation process removes characters that are invalid for XML encoding.
Hexadecimal characters that are valid include: #x9, #xA, #xD, [#x20-#xD7FF], [#xE000-#xFFFD], [#x10000-#x10FFFF], and any Unicode character; excluding the surrogate blocks FFFE and FFFF.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentNullException | The |