void Process(SgmlReader reader, string uri, bool loadAsStream) { if (uri == null) { reader.InputStream = Console.In; } else if (loadAsStream) { Uri location = new Uri(uri); if (location.IsFile) { reader.InputStream = new StreamReader(uri); } else { WebRequest wr = WebRequest.Create(location); reader.InputStream = new StreamReader(wr.GetResponse().GetResponseStream()); } } else { reader.Href = uri; } if (debug) { Debug(reader); reader.Close(); return; } if (crawl) { StartCrawl(reader, uri, basify); return; } if (this.encoding == null) { this.encoding = reader.GetEncoding(); } XmlTextWriter w = null; if (output != null) { w = new XmlTextWriter(output, this.encoding); } else { w = new XmlTextWriter(Console.Out); } if (formatted) w.Formatting = Formatting.Indented; if (!noxmldecl) { w.WriteStartDocument(); } if (testdoc) { XmlDocument doc = new XmlDocument(); try { doc.Load(reader); doc.WriteTo(w); } catch (XmlException e) { Console.WriteLine("Error:" + e.Message); Console.WriteLine("at line " + e.LineNumber + " column " + e.LinePosition); } } else { reader.Read(); while (!reader.EOF) { w.WriteNode(reader, true); } } w.Flush(); w.Close(); }
void Process(SgmlReader reader, string uri) { if (uri == null) { reader.InputStream = Console.In; } else { reader.Href = uri; } this.encoding ??= reader.GetEncoding(); XmlTextWriter w = output != null ? new XmlTextWriter(output, this.encoding) : new XmlTextWriter(Console.Out); if (formatted) { w.Formatting = Formatting.Indented; } if (!noxmldecl) { w.WriteStartDocument(); } reader.Read(); while (!reader.EOF) { w.WriteNode(reader, true); } w.Flush(); w.Close(); }
private void Process(SgmlReader reader, string uri) { if (uri == null) { reader.InputStream = Console.In; } else { reader.Href = uri; } encoding ??= reader.GetEncoding(); if (noUtf8Bom && encoding.Equals(Encoding.UTF8)) { encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); } XmlTextWriter w = output != null ? new XmlTextWriter(output, encoding) : new XmlTextWriter(Console.Out); using (w) { if (formatted) { w.Formatting = Formatting.Indented; } if (!noxmldecl) { w.WriteStartDocument(); } reader.Read(); while (!reader.EOF) { w.WriteNode(reader, true); } w.Flush(); } }