/// <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="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. /// </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. /// </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> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Uri source, ICredentials credentials, IWebProxy proxy) { //------------------------------------------------------------ // Create safe navigator using auto-detection of encoding //------------------------------------------------------------ return(SyndicationEncodingUtility.CreateSafeNavigator(source, new WebRequestOptions(credentials, proxy))); }
/// <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="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. /// </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. /// </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, ICredentials credentials, IWebProxy proxy, Encoding encoding) { //------------------------------------------------------------ // Create safe navigator using the specified encoding //------------------------------------------------------------ return(SyndicationEncodingUtility.CreateSafeNavigator(source, new WebRequestOptions(credentials, proxy), encoding)); }
/// <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> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options) { //------------------------------------------------------------ // Create safe navigator using auto-detection of encoding //------------------------------------------------------------ return(SyndicationEncodingUtility.CreateSafeNavigator(source, options, null)); }
//============================================================ // WEB RESOURCE PARSING METHODS //============================================================ #region CreateSafeNavigator(string xml) /// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied XML data. /// </summary> /// <param name="xml">The XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied XML data. /// The supplied <paramref name="xml"/> data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="xml"/> data is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xml"/> data is an empty string.</exception> public static XPathNavigator CreateSafeNavigator(string xml) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ XPathNavigator navigator = null; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNullOrEmptyString(xml, "xml"); //------------------------------------------------------------ // Encode XML data to convert invalid XML hexadecimal values //------------------------------------------------------------ string safeXml = SyndicationEncodingUtility.RemoveInvalidXmlHexadecimalCharacters(xml); //------------------------------------------------------------ // Create navigator against safely encoded XML data //------------------------------------------------------------ using (StringReader reader = new StringReader(safeXml)) { XPathDocument document = new XPathDocument(reader); navigator = document.CreateNavigator(); } return(navigator); }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Stream"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="stream"/>. /// The supplied <paramref name="stream"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <remarks> /// The character encoding of the supplied <paramref name="stream"/> is automatically determined based on the <i>encoding</i> attribute of the XML document declaration. /// If the character encoding cannot be determined, a default encoding of <see cref="Encoding.UTF8"/> is used. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Stream stream) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Encoding encoding = Encoding.UTF8; byte[] buffer = null; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); //------------------------------------------------------------ // Extract stream data as an array of bytes //------------------------------------------------------------ buffer = SyndicationEncodingUtility.GetStreamBytes(stream); //------------------------------------------------------------ // Determine encoding of the XML data //------------------------------------------------------------ encoding = SyndicationEncodingUtility.GetXmlEncoding(buffer); //------------------------------------------------------------ // Attempt to return navigator for supplied stream //------------------------------------------------------------ using (MemoryStream memoryStream = new MemoryStream(buffer)) { return(SyndicationEncodingUtility.CreateSafeNavigator(memoryStream, encoding)); } }
/// <summary> /// Returns an <see cref="Encoding"/> that represents the XML character encoding for the supplied <see cref="Stream"/>. /// </summary> /// <param name="stream">A <see cref="Stream"/> that represents an XML data source to determine the character encoding for.</param> /// <returns> /// A <see cref="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 <see cref="Encoding.UTF8"/>. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> public static Encoding GetXmlEncoding(Stream stream) { Guard.ArgumentNotNull(stream, "stream"); using (StreamReader reader = new StreamReader(stream)) { return(SyndicationEncodingUtility.GetXmlEncoding(reader.ReadToEnd())); } }
/// <summary> /// Extracts the character encoding for the content type of the supplied <see cref="HttpRequest"/>. /// </summary> /// <param name="request">The HTTP values sent by a client during a Web request.</param> /// <returns> /// A <see cref="Encoding"/> that represents character encoding of the Content-Type <i>charset</i> attribute. /// If the <i>charset</i> attribute is unavailable or invalid, returns <b>null</b>. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="request"/> is a null reference (Nothing in Visual Basic).</exception> /*public static Encoding GetCharacterEncoding(HttpRequest request) * { * Encoding contentEncoding = null; * * Guard.ArgumentNotNull(request, "request"); * * if (!String.IsNullOrEmpty(request.ContentType)) * { * if (request.ContentType.Contains(";")) * { * string[] contentTypeParts = request.ContentType.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); * if (contentTypeParts != null && contentTypeParts.Length > 0) * { * for (int i = 0; i < contentTypeParts.Length; i++) * { * string typePart = contentTypeParts[i].Trim(); * if (typePart.Contains("=")) * { * string[] nameValuePair = typePart.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); * if (nameValuePair != null && nameValuePair.Length == 2) * { * string name = nameValuePair[0].Trim(); * string value = nameValuePair[1].Trim(); * * if (String.Compare(name, "charset", StringComparison.OrdinalIgnoreCase) == 0) * { * try * { * contentEncoding = Encoding.GetEncoding(value); * } * catch (ArgumentException) * { * return null; * } * } * } * } * } * } * } * } * * return contentEncoding; * }*/ /// <summary> /// Returns an <see cref="Encoding"/> that represents the XML character encoding for the supplied array of bytes. /// </summary> /// <param name="data">An array of bytes that represents an XML data source to determine the character encoding for.</param> /// <returns> /// A <see cref="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 <see cref="Encoding.UTF8"/>. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception> public static Encoding GetXmlEncoding(byte[] data) { Guard.ArgumentNotNull(data, "data"); using (MemoryStream stream = new MemoryStream(data)) { return(SyndicationEncodingUtility.GetXmlEncoding(stream)); } }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Stream"/> using the specified <see cref="Encoding"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <param name="encoding">A <see cref="Encoding"/> object that indicates the character encoding to use when reading the supplied <paramref name="stream"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="stream"/>. /// The supplied <paramref name="stream"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="encoding"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Stream stream, Encoding encoding) { Guard.ArgumentNotNull(stream, "stream"); Guard.ArgumentNotNull(encoding, "encoding"); using (StreamReader reader = new StreamReader(stream, encoding)) { return(SyndicationEncodingUtility.CreateSafeNavigator(reader.ReadToEnd())); } }
//============================================================ // PUBLIC METHODS //============================================================ #region CreateNavigator() /// <summary> /// Initializes a read-only <see cref="XPathNavigator"/> object for navigating through the auto-discoverable syndicated content located at the <see cref="Source">endpoint location</see>. /// </summary> /// <returns>A read-only <see cref="XPathNavigator"/> object for navigating the auto-discoverable syndicated content.</returns> /// <exception cref="ArgumentNullException">The <see cref="Source"/> is a null reference (Nothing in Visual Basic).</exception> public XPathNavigator CreateNavigator() { //------------------------------------------------------------ // Validate that endpoint has a valid source //------------------------------------------------------------ Guard.ArgumentNotNull(this.Source, "Source"); //------------------------------------------------------------ // Return a safe navigator for endpoint //------------------------------------------------------------ return(SyndicationEncodingUtility.CreateSafeNavigator(this.Source, new WebRequestOptions())); }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="TextReader"/>. /// </summary> /// <param name="reader">The <see cref="TextReader"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="reader"/>. /// The supplied <paramref name="reader"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="reader"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(TextReader reader) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(reader, "reader"); //------------------------------------------------------------ // Attempt to return navigator for supplied reader //------------------------------------------------------------ return(SyndicationEncodingUtility.CreateSafeNavigator(reader.ReadToEnd())); }
/// <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="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</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, WebRequestOptions options) { WebResponse response = null; Guard.ArgumentNotNull(source, "source"); WebRequest webRequest = SyndicationEncodingUtility.CreateWebRequest(source, options); if (webRequest != null) { response = webRequest.GetResponse(); } return(response); }
/// <summary> /// Returns an <see cref="Encoding"/> that represents the XML character encoding for the supplied <see cref="Stream"/>. /// </summary> /// <param name="stream">A <see cref="Stream"/> that represents an XML data source to determine the character encoding for.</param> /// <returns> /// A <see cref="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 <see cref="Encoding.UTF8"/>. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> public static Encoding GetXmlEncoding(Stream stream) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); //------------------------------------------------------------ // Read the stream contents and return character encoding //------------------------------------------------------------ using (StreamReader reader = new StreamReader(stream)) { return(SyndicationEncodingUtility.GetXmlEncoding(reader.ReadToEnd())); } }
/// <summary> /// Returns an <see cref="Encoding"/> that represents the XML character encoding for the supplied array of bytes. /// </summary> /// <param name="data">An array of bytes that represents an XML data source to determine the character encoding for.</param> /// <returns> /// A <see cref="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 <see cref="Encoding.UTF8"/>. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception> public static Encoding GetXmlEncoding(byte[] data) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(data, "data"); //------------------------------------------------------------ // Create stream using data and return character encoding //------------------------------------------------------------ using (MemoryStream stream = new MemoryStream(data)) { return(SyndicationEncodingUtility.GetXmlEncoding(stream)); } }
/// <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) { 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 (string.IsNullOrEmpty(contentEncoding)) { stream = response.GetResponseStream(); } else { 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> /// Creates a <see cref="XPathNavigator"/> against the supplied XML data. /// </summary> /// <param name="xml">The XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied XML data. /// The supplied <paramref name="xml"/> data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="xml"/> data is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xml"/> data is an empty string.</exception> public static XPathNavigator CreateSafeNavigator(string xml) { XPathNavigator navigator = null; Guard.ArgumentNotNullOrEmptyString(xml, "xml"); string safeXml = SyndicationEncodingUtility.RemoveInvalidXmlHexadecimalCharacters(xml); using (StringReader reader = new StringReader(safeXml)) { XPathDocument document = new XPathDocument(reader); navigator = document.CreateNavigator(); } return(navigator); }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Stream"/> using the specified <see cref="Encoding"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <param name="encoding">A <see cref="Encoding"/> object that indicates the character encoding to use when reading the supplied <paramref name="stream"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="stream"/>. /// The supplied <paramref name="stream"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="encoding"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Stream stream, Encoding encoding) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); Guard.ArgumentNotNull(encoding, "encoding"); //------------------------------------------------------------ // Attempt to return navigator for supplied stream and encoding //------------------------------------------------------------ using (StreamReader reader = new StreamReader(stream, encoding)) { return(SyndicationEncodingUtility.CreateSafeNavigator(reader.ReadToEnd())); } }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Stream"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="stream"/>. /// The supplied <paramref name="stream"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <remarks> /// The character encoding of the supplied <paramref name="stream"/> is automatically determined based on the <i>encoding</i> attribute of the XML document declaration. /// If the character encoding cannot be determined, a default encoding of <see cref="Encoding.UTF8"/> is used. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Stream stream) { Encoding encoding = Encoding.UTF8; byte[] buffer = null; Guard.ArgumentNotNull(stream, "stream"); buffer = SyndicationEncodingUtility.GetStreamBytes(stream); encoding = SyndicationEncodingUtility.GetXmlEncoding(buffer); using (MemoryStream memoryStream = new MemoryStream(buffer)) { return(SyndicationEncodingUtility.CreateSafeNavigator(memoryStream, encoding)); } }
/// <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))); }
/// <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="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. /// </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. /// </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, ICredentials credentials, IWebProxy proxy, Encoding encoding) { return(SyndicationEncodingUtility.CreateSafeNavigator(source, new WebRequestOptions(credentials, proxy), encoding)); }
/// <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> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options) { return(SyndicationEncodingUtility.CreateSafeNavigator(source, options, null)); }
/// <summary> /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="TextReader"/>. /// </summary> /// <param name="reader">The <see cref="TextReader"/> object that contains the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param> /// <returns> /// An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="reader"/>. /// The supplied <paramref name="reader"/> XML data is parsed to remove invalid XML characters that would normally prevent /// a navigator from being created. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="reader"/> is a null reference (Nothing in Visual Basic).</exception> public static XPathNavigator CreateSafeNavigator(TextReader reader) { Guard.ArgumentNotNull(reader, "reader"); return(SyndicationEncodingUtility.CreateSafeNavigator(reader.ReadToEnd())); }
/// <summary> /// Initializes a read-only <see cref="XPathNavigator"/> object for navigating through the auto-discoverable syndicated content located at the <see cref="Source">endpoint location</see>. /// </summary> /// <returns>A read-only <see cref="XPathNavigator"/> object for navigating the auto-discoverable syndicated content.</returns> /// <exception cref="ArgumentNullException">The <see cref="Source"/> is a null reference (Nothing in Visual Basic).</exception> public XPathNavigator CreateNavigator() { Guard.ArgumentNotNull(this.Source, "Source"); return(SyndicationEncodingUtility.CreateSafeNavigator(this.Source, new WebRequestOptions())); }