Ejemplo n.º 1
0
        /// <summary>
        /// Builds a document from the content of the web response.
        /// A warning is logged if an exception is thrown while parsing the XML content
        /// (for instance when the content is not a valid XML and can't be parsed).
        /// @throws IOException if the page could not be created
        /// @throws SAXException if the parsing fails
        /// @throws ParserConfigurationException if a DocumentBuilder cannot be created
        /// </summary>
        /// <param name="WebResponse">the response from the server</param>
        /// <returns>the parse result</returns>
        public static XmlDocument BuildDocument(WebResponse webResponse)
        {
            XmlDocument xml = new XmlDocument();

            if (webResponse == null)
            {
                return(xml);
            }

            InputStreamReader reader = new InputStreamReader(webResponse.GetContentAsStream(), Encoding.GetEncoding(webResponse.GetContentCharset()));

            // we have to do the blank input check and the parsing in one step
            TrackBlankContentReader tracker = new TrackBlankContentReader(reader);

            try
            {
                xml.Load(tracker);
                return(xml);
            }
            catch (XmlException e)
            {
                if (tracker.WasBlank)
                {
                    return(new XmlDocument());
                }
                throw e;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a document from the content of the web response.
        /// A warning is logged if an exception is thrown while parsing the XML content
        /// (for instance when the content is not a valid XML and can't be parsed).
        /// @throws IOException if the page could not be created
        /// @throws SAXException if the parsing fails
        /// @throws ParserConfigurationException if a DocumentBuilder cannot be created
        /// </summary>
        /// <param name="WebResponse">the response from the server</param>
        /// <returns>the parse result</returns>
        public static XmlDocument BuildDocument(WebResponse webResponse)
        {
            XmlDocument xml = new XmlDocument();
            if (webResponse == null)
            {
                return xml;
            }

            InputStreamReader reader = new InputStreamReader(webResponse.GetContentAsStream(), Encoding.GetEncoding(webResponse.GetContentCharset()));

            // we have to do the blank input check and the parsing in one step
            TrackBlankContentReader tracker = new TrackBlankContentReader(reader);

            try
            {
                xml.Load(tracker);
                return xml;
            }
            catch (XmlException e)
            {
                if (tracker.WasBlank)
                {
                    return new XmlDocument();
                }
                throw e;
            }
        }