public void Open(Entity parent, Uri baseUri)
        {
            Parent = parent;
            if (parent != null)
            {
                this.Html = parent.Html;
            }
            this.Line = 1;
            if (Internal)
            {
                if (this.Literal != null)
                {
                    this.stm = new StringReader(this.Literal);
                }
            }
            else if (this.Uri == null)
            {
                this.Error("Unresolvable entity '{0}'", this.Name);
            }
            else
            {
                if (baseUri != null)
                {
                    this.resolvedUri = new Uri(baseUri, this.Uri);
                }
                else
                {
                    this.resolvedUri = new Uri(this.Uri);
                }

                Stream   stream = null;
                Encoding e      = Encoding.Default;
                switch (this.resolvedUri.Scheme)
                {
                case "file":
                {
                    string path = this.resolvedUri.LocalPath;
                    stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                }
                break;

                default:
                    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(ResolvedUri);
                    wr.UserAgent = "Mozilla/4.0 (compatible;);";
                    wr.Timeout   = 10000;
                    if (Proxy != null)
                    {
                        wr.Proxy = new WebProxy(Proxy);
                    }
                    wr.PreAuthenticate = false;

                    wr.Credentials = CredentialCache.DefaultCredentials;

                    WebResponse resp   = wr.GetResponse();
                    Uri         actual = resp.ResponseUri;
                    if (actual.AbsoluteUri != this.resolvedUri.AbsoluteUri)
                    {
                        this.resolvedUri = actual;
                    }
                    string contentType = resp.ContentType.ToLower();
                    string mimeType    = contentType;
                    int    i           = contentType.IndexOf(';');
                    if (i >= 0)
                    {
                        mimeType = contentType.Substring(0, i);
                    }
                    if (StringUtilities.EqualsIgnoreCase(mimeType, "text/html"))
                    {
                        this.Html = true;
                    }

                    i = contentType.IndexOf("charset");
                    e = Encoding.Default;
                    if (i >= 0)
                    {
                        int j = contentType.IndexOf("=", i);
                        int k = contentType.IndexOf(";", j);
                        if (k < 0)
                        {
                            k = contentType.Length;
                        }
                        if (j > 0)
                        {
                            j++;
                            string charset = contentType.Substring(j, k - j).Trim();
                            try
                            {
                                e = Encoding.GetEncoding(charset);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    stream = resp.GetResponseStream();
                    break;
                }
                this.weOwnTheStream = true;
                HtmlStream html = new HtmlStream(stream, e);
                this.encoding = html.Encoding;
                this.stm      = html;
            }
        }
        public void Open(Entity parent, Uri baseUri)
        {
            Parent = parent;
            if (parent != null) this.Html = parent.Html;
            this.Line = 1;
            if (Internal)
            {
                if (this.Literal != null)
                    this.stm = new StringReader(this.Literal);
            }
            else if (this.Uri == null)
            {
                this.Error("Unresolvable entity '{0}'", this.Name);
            }
            else
            {
                if (baseUri != null)
                {
                    this.resolvedUri = new Uri(baseUri, this.Uri);
                }
                else
                {
                    this.resolvedUri = new Uri(this.Uri);
                }

                Stream stream = null;
                Encoding e = Encoding.Default;
                switch (this.resolvedUri.Scheme)
                {
                    case "file":
                        {
                            string path = this.resolvedUri.LocalPath;
                            stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                        }
                        break;
                    default:
                        HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(ResolvedUri);
                        wr.UserAgent = "Mozilla/4.0 (compatible;);";
                        wr.Timeout = 10000;
                        if (Proxy != null) wr.Proxy = new WebProxy(Proxy);
                        wr.PreAuthenticate = false;

                        wr.Credentials = CredentialCache.DefaultCredentials;

                        WebResponse resp = wr.GetResponse();
                        Uri actual = resp.ResponseUri;
                        if (actual.AbsoluteUri != this.resolvedUri.AbsoluteUri)
                        {
                            this.resolvedUri = actual;
                        }
                        string contentType = resp.ContentType.ToLower();
                        string mimeType = contentType;
                        int i = contentType.IndexOf(';');
                        if (i >= 0)
                        {
                            mimeType = contentType.Substring(0, i);
                        }
                        if (StringUtilities.EqualsIgnoreCase(mimeType, "text/html"))
                        {
                            this.Html = true;
                        }

                        i = contentType.IndexOf("charset");
                        e = Encoding.Default;
                        if (i >= 0)
                        {
                            int j = contentType.IndexOf("=", i);
                            int k = contentType.IndexOf(";", j);
                            if (k < 0) k = contentType.Length;
                            if (j > 0)
                            {
                                j++;
                                string charset = contentType.Substring(j, k - j).Trim();
                                try
                                {
                                    e = Encoding.GetEncoding(charset);
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                        stream = resp.GetResponseStream();
                        break;

                }
                this.weOwnTheStream = true;
                HtmlStream html = new HtmlStream(stream, e);
                this.encoding = html.Encoding;
                this.stm = html;
            }
        }