/// <summary>
        /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="encoding">A <see cref="Encoding"/> object that indicates the expected character encoding of the supplied <paramref name="source"/>. This value can be <b>null</b>.</param>
        /// <returns>
        ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>.
        ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent
        ///     a navigator from being created.
        /// </returns>
        /// <remarks>
        ///     If the <paramref name="encoding"/> is <b>null</b>, the character encoding of the supplied <paramref name="source"/> is determined automatically.
        ///     Otherwise the specified <paramref name="encoding"/> is used when reading the XML data represented by the supplied <paramref name="source"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options, Encoding encoding)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            using (WebResponse response = SyndicationEncodingUtility.CreateWebResponse(source, options))
            {
                Stream          stream       = null;
                HttpWebResponse httpResponse = response as HttpWebResponse;

                if (httpResponse != null)
                {
                    string contentEncoding = httpResponse.ContentEncoding.ToUpperInvariant();

                    if (contentEncoding.Contains("GZIP"))
                    {
                        stream = new GZipStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                    }
                    else if (contentEncoding.Contains("DEFLATE"))
                    {
                        stream = new DeflateStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                    }
                    else
                    {
                        stream = httpResponse.GetResponseStream();
                    }
                }
                else
                {
                    stream = response.GetResponseStream();
                }

                if (encoding != null)
                {
                    return(SyndicationEncodingUtility.CreateSafeNavigator(stream, encoding));
                }
                else
                {
                    return(SyndicationEncodingUtility.CreateSafeNavigator(stream));
                }
            }
        }
 /// <summary>
 /// Returns the <see cref="WebResponse"/> to a request for a resource located at the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
 /// </summary>
 /// <param name="source">A <see cref="Uri"/> that points to the location of the resource to be retrieved.</param>
 /// <param name="credentials">
 ///     A <see cref="ICredentials"/> that provides the proper set of credentials to the <paramref name="source"/> resource when required.
 ///     If <paramref name="credentials"/> is <b>null</b>, request is made using the default application credentials if supported by the underlying protocol.
 /// </param>
 /// <param name="proxy">
 ///     A <see cref="IWebProxy"/> that provides proxy access to the <paramref name="source"/> resource when required.
 ///     If <paramref name="proxy"/> is <b>null</b>, request is made using the <see cref="WebRequest"/> default proxy settings if supported by the underlying protocol.
 /// </param>
 /// <returns>
 ///     An <see cref="WebResponse"/> that contains the response from the requested resource. If unable to create a <see cref="WebResponse"/> for
 ///     the requested <paramref name="source"/>, returns a <b>null</b> reference (Nothing in Visual Basic).
 /// </returns>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public static WebResponse CreateWebResponse(Uri source, ICredentials credentials, IWebProxy proxy)
 {
     return(SyndicationEncodingUtility.CreateWebResponse(source, new WebRequestOptions(credentials, proxy)));
 }