本文整理匯總了C#中Sgml.SgmlReader.Read方法的典型用法代碼示例。如果您正苦於以下問題:C# SgmlReader.Read方法的具體用法?C# SgmlReader.Read怎麽用?C# SgmlReader.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sgml.SgmlReader
的用法示例。
在下文中一共展示了SgmlReader.Read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ParseHtml
// Creates XmlDocument from html content and return it with rootitem "<root>".
public static XmlDocument ParseHtml(string sContent)
{
StringReader sr = new StringReader("<root>" + sContent + "</root>");
SgmlReader reader = new SgmlReader();
reader.WhitespaceHandling = WhitespaceHandling.All;
reader.CaseFolding = Sgml.CaseFolding.ToLower;
reader.InputStream = sr;
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
w.WriteStartDocument();
reader.Read();
while (!reader.EOF)
{
w.WriteNode(reader, true);
}
w.Flush();
w.Close();
sw.Flush();
// create document
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.XmlResolver = null;
doc.LoadXml(sw.ToString());
reader.Close();
return doc;
}
示例2: GetWellFormedHTML
public static string GetWellFormedHTML(string html, string xpathNavPath)
{
// StreamReader sReader = null;
StringWriter sw = null;
SgmlReader reader = null;
XmlTextWriter writer = null;
try
{
// if (uri == String.Empty) uri = "http://www.XMLforASP.NET";
// HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
// HttpWebResponse res = (HttpWebResponse)req.GetResponse();
// sReader = new StreamReader(res.GetResponseStream());
reader = new SgmlReader();
reader.DocType = "HTML";
reader.InputStream = new StringReader(html);
sw = new StringWriter();
writer = new XmlTextWriter(sw);
writer.Formatting = Formatting.Indented;
//writer.WriteStartElement("Test");
while (reader.Read())
{
if (reader.NodeType != XmlNodeType.Whitespace)
{
writer.WriteNode(reader, true);
}
}
//writer.WriteEndElement();
if (xpathNavPath == null)
{
string sr = sw.ToString();
sr = sr.Replace("\r", "\n");
sr = sr.Replace("\n\n", "\n");
return sr;
}
else
{ //Filter out nodes from HTML
StringBuilder sb = new StringBuilder();
XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator nodes = nav.Select(xpathNavPath);
while (nodes.MoveNext())
{
sb.Append(nodes.Current.Value + "\n");
}
string sr = sb.ToString();
sr = sr.Replace("\r", "\n");
sr = sr.Replace("\n\n", "\n");
return sr;
}
}
catch (Exception exp)
{
writer.Close();
reader.Close();
sw.Close();
// sReader.Close();
return exp.Message;
}
}
示例3: FindImgs
internal static ImageInfo[] FindImgs(
string htmlCode)
{
var r =
new SgmlReader
{
DocType = @"HTML",
InputStream = new StringReader(htmlCode)
};
var al = new List<ImageInfo>();
//find <img src=""
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element)
{
if (string.Compare(r.Name, @"img", StringComparison.OrdinalIgnoreCase) == 0)
{
if (r.HasAttributes)
{
var ii = new ImageInfo();
while (r.MoveToNextAttribute())
{
switch (r.Name.ToLowerInvariant())
{
case @"src":
ii.Source = r.Value;
break;
case @"width":
ii.Width = ConvertHelper.ToInt32(r.Value);
break;
case @"height":
ii.Height = ConvertHelper.ToInt32(r.Value);
break;
}
}
// --
if (!string.IsNullOrEmpty(ii.Source))
{
al.Add(ii);
}
}
}
}
}
return al.ToArray();
}
示例4: Debug
void Debug(SgmlReader sr)
{
NodeTypeFlags[] AllowedContentMap = new NodeTypeFlags[19] {
NodeTypeFlags.None, // none
NodeTypeFlags.Element | NodeTypeFlags.Attribute | NodeTypeFlags.Text | NodeTypeFlags.CDATA | NodeTypeFlags.EntityReference | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Comment | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.EndElement, // element
NodeTypeFlags.Text | NodeTypeFlags.EntityReference, // attribute
NodeTypeFlags.None, // text
NodeTypeFlags.None, // cdata
NodeTypeFlags.None, // entity reference
NodeTypeFlags.None, // entity
NodeTypeFlags.None, // processing instruction
NodeTypeFlags.None, // comment
NodeTypeFlags.Comment | NodeTypeFlags.DocumentType | NodeTypeFlags.Element | NodeTypeFlags.EndElement | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.XmlDeclaration, // document
NodeTypeFlags.None, // document type
NodeTypeFlags.None, // document fragment (not expecting these)
NodeTypeFlags.None, // notation
NodeTypeFlags.None, // whitespace
NodeTypeFlags.None, // signification whitespace
NodeTypeFlags.None, // end element
NodeTypeFlags.None, // end entity
NodeTypeFlags.None, // filler
NodeTypeFlags.None, // xml declaration.
};
Stack s = new Stack();
while (sr.Read()) {
if (sr.NodeType == XmlNodeType.EndElement) {
s.Pop();
}
if (s.Count > 0) {
XmlNodeType pt = (XmlNodeType)s.Peek();
NodeTypeFlags p = NodeTypeMap[(int)pt];
NodeTypeFlags f = NodeTypeMap[(int)sr.NodeType];
if ((AllowedContentMap[(int)pt]& f) != f) {
Console.WriteLine("Invalid content!!");
}
}
if (s.Count != sr.Depth-1) {
Console.WriteLine("Depth is wrong!");
}
if ( (sr.NodeType == XmlNodeType.Element && !sr.IsEmptyElement) ||
sr.NodeType == XmlNodeType.Document) {
s.Push(sr.NodeType);
}
for (int i = 1; i < sr.Depth; i++)
Console.Write(" ");
Console.Write(sr.NodeType.ToString() + " " + sr.Name);
if (sr.NodeType == XmlNodeType.Element && sr.AttributeCount > 0) {
sr.MoveToAttribute(0);
Console.Write(" (" + sr.Name+"="+sr.Value + ")");
sr.MoveToElement();
}
if (sr.Value != null) {
Console.Write(" " + sr.Value.Replace("\n"," ").Replace("\r",""));
}
Console.WriteLine();
}
}
示例5: ConvertHtmlToXHtml
/// <summary>
/// Converts the specified html into XHTML compliant text.
/// </summary>
/// <param name="reader">sgml reader.</param>
/// <param name="html">html to convert.</param>
/// <param name="converter">The converter.</param>
/// <returns></returns>
/// ///
private static string ConvertHtmlToXHtml(SgmlReader reader, string html, Converter<string, string> converter)
{
reader.DocType = "html";
reader.WhitespaceHandling = WhitespaceHandling.All;
// Hack to fix SF bug #1678030
html = RemoveNewLineBeforeCDATA(html);
reader.InputStream = new StringReader("<html>" + html + "</html>");
reader.CaseFolding = CaseFolding.ToLower;
StringWriter writer = new StringWriter();
XmlWriter xmlWriter = null;
try
{
xmlWriter = new XmlTextWriter(writer);
bool insideAnchor = false;
bool skipRead = false;
while ((skipRead || reader.Read()) && !reader.EOF)
{
skipRead = false;
switch(reader.NodeType)
{
case XmlNodeType.Element:
//Special case for anchor tags for the time being.
//We need some way to communicate which elements the current node is nested within
if (reader.IsEmptyElement)
{
xmlWriter.WriteStartElement(reader.LocalName);
xmlWriter.WriteAttributes(reader, true);
if (reader.LocalName == "a" || reader.LocalName == "script")
xmlWriter.WriteFullEndElement();
else
xmlWriter.WriteEndElement();
}
else
{
if (reader.LocalName == "a")
insideAnchor = true;
xmlWriter.WriteStartElement(reader.LocalName);
xmlWriter.WriteAttributes(reader, true);
}
break;
case XmlNodeType.Text:
string text = reader.Value;
if (converter != null && !insideAnchor)
xmlWriter.WriteRaw(converter(text));
else
xmlWriter.WriteString(text);
break;
case XmlNodeType.EndElement:
if (reader.LocalName == "a")
insideAnchor = false;
if (reader.LocalName == "a" || reader.LocalName == "script")
xmlWriter.WriteFullEndElement();
else
xmlWriter.WriteEndElement();
break;
default:
xmlWriter.WriteNode(reader, true);
skipRead = true;
break;
}
}
}
finally
{
if (xmlWriter != null)
{
xmlWriter.Close();
}
}
string xml = writer.ToString();
return xml.Substring("<html>".Length, xml.Length - "<html></html>".Length);
}
示例6: GetAttributeValues
public static IEnumerable<string> GetAttributeValues(this string html, string tagName, string attributeName)
{
var reader = new SgmlReader
{
DocType = "html",
WhitespaceHandling = WhitespaceHandling.All,
InputStream = new StringReader(string.Format("<html>{0}</html>", html))
};
while (reader.Read() && !reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element && reader.LocalName == tagName)
{
yield return reader.GetAttribute(attributeName);
}
}
}
示例7: ConvertCommentToMarkdown
private static string ConvertCommentToMarkdown(string body)
{
var sb = new StringBuilder();
var sgmlReader = new SgmlReader
{
InputStream = new StringReader(body),
DocType = "HTML",
WhitespaceHandling = WhitespaceHandling.Significant,
CaseFolding = CaseFolding.ToLower
};
bool outputEndElement = false;
int indentLevel = 0;
while (sgmlReader.Read())
{
switch (sgmlReader.NodeType)
{
case XmlNodeType.Text:
if (indentLevel > 0)
sb.Append("\t");
sb.AppendLine(sgmlReader.Value);
break;
case XmlNodeType.Element:
switch (sgmlReader.LocalName)
{
case "h1":
sb.Append("## ");
break;
case "br":
sb.AppendLine(" ");
break;
case "a":
if (sgmlReader.MoveToAttribute("href"))
{
string url = sgmlReader.Value;
sgmlReader.Read();
sb.AppendFormat("[{0}]({1})", sgmlReader.Value, url);
}
break;
case "html":
break;
case "strong":
case "b":
sb.AppendFormat("**{0}**", sgmlReader.Value);
break;
case "i":
case "em":
sb.AppendFormat("_{0}_", sgmlReader.Value);
break;
case "li":
sb.AppendFormat("- {0}", sgmlReader.Value);
break;
case "pre":
case "code":
case "quote":
indentLevel = 1;
break;
case "ul":
case "ol":
case "img":
break;
default:
outputEndElement = true;
sb.Append("<").Append(sgmlReader.LocalName);
break;
}
break;
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Whitespace:
case XmlNodeType.CDATA:
break;
case XmlNodeType.EndElement:
indentLevel = 0;
if (outputEndElement)
sb.Append(">");
outputEndElement = false;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
return sb.ToString();
}
示例8: TransformHtmlToXHTML
public static string TransformHtmlToXHTML(string inputHtml)
{
var sgmlReader = new SgmlReader { DocType = "HTML", };
var stringReader = new StringReader(inputHtml);
sgmlReader.InputStream = stringReader;
var stringWriter = new StringWriter();
using (var xmlWriter = new XmlTextWriter(stringWriter))
{
sgmlReader.Read();
while (!sgmlReader.EOF)
{
xmlWriter.WriteNode(sgmlReader, true);
}
}
return RemoveCopyOfImage(stringWriter.ToString());
}
示例9: Process
void Process(SgmlReader reader, string uri)
{
if (uri == null) {
reader.InputStream = Console.In;
} else {
reader.Href = uri;
}
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();
}
reader.Read();
while (!reader.EOF) {
w.WriteNode(reader, true);
}
w.Flush();
w.Close();
}
示例10: RunTest
void RunTest(SgmlReader reader, int line, string args, string input, string expectedOutput)
{
try {
bool testdoc = false;
bool testclone = false;
bool format = true;
bool ignore = false;
foreach(string arg in args.Split(' ')) {
string sarg = arg.Trim();
if(sarg.Length == 0)
continue;
if(sarg[0] == '-') {
switch(sarg.Substring(1)) {
case "html":
reader.DocType = "html";
break;
case "lower":
reader.CaseFolding = CaseFolding.ToLower;
break;
case "upper":
reader.CaseFolding = CaseFolding.ToUpper;
break;
case "testdoc":
testdoc = true;
break;
case "testclone":
testclone = true;
break;
case "noformat":
format = false;
break;
case "ignore":
ignore = true;
break;
}
}
}
this.tests++;
if(ignore) {
this.ignored++;
return;
}
reader.InputStream = new StringReader(input);
if(format) {
reader.WhitespaceHandling = WhitespaceHandling.None;
} else {
reader.WhitespaceHandling = WhitespaceHandling.All;
}
StringWriter output = new StringWriter();
XmlTextWriter w = new XmlTextWriter(output);
if(format) {
w.Formatting = Formatting.Indented;
}
if(testdoc) {
XmlDocument doc = new XmlDocument();
doc.Load(reader);
doc.WriteTo(w);
} else if(testclone) {
XmlDocument doc = new XmlDocument();
doc.Load(reader);
XmlNode clone = doc.Clone();
clone.WriteTo(w);
} else {
reader.Read();
while(!reader.EOF) {
w.WriteNode(reader, true);
}
}
w.Close();
string actualOutput = output.ToString();
// validate output
using(StringReader source = new StringReader(actualOutput)) {
XmlDocument doc = new XmlDocument();
doc.Load(source);
}
// compare output
if(actualOutput.Trim().Replace("\r", "") != expectedOutput.Trim().Replace("\r", "")) {
Console.WriteLine();
Console.WriteLine("ERROR: Test failed on line {0}", line);
Console.WriteLine("---- Expected output");
Console.Write(expectedOutput);
Console.WriteLine("---- Actual output");
Console.WriteLine(actualOutput);
} else {
this.passed++;
}
} catch(Exception e) {
Console.WriteLine("FATAL ERROR: Test threw an exception on line {0}", line);
Console.WriteLine(e.Message);
Console.WriteLine(e.ToString());
Console.WriteLine("---- Input");
Console.Write(input);
}
}
示例11: RunTest
void RunTest(SgmlReader reader, int line, string args, string input, string expectedOutput)
{
bool testdoc = false;
foreach (string arg in args.Split(' ')){
string sarg = arg.Trim();
if (sarg.Length==0) continue;
if (sarg[0] == '-'){
switch (sarg.Substring(1)){
case "html":
reader.DocType = "html";
break;
case "lower":
reader.CaseFolding = CaseFolding.ToLower;
break;
case "upper":
reader.CaseFolding = CaseFolding.ToUpper;
break;
case "testdoc":
testdoc = true;
break;
}
}
}
this.tests++;
reader.InputStream = new StringReader(input);
reader.WhitespaceHandling = WhitespaceHandling.None;
StringWriter output = new StringWriter();
XmlTextWriter w = new XmlTextWriter(output);
w.Formatting = Formatting.Indented;
if (testdoc) {
XmlDocument doc = new XmlDocument();
doc.Load(reader);
doc.WriteTo(w);
} else {
reader.Read();
while (!reader.EOF) {
w.WriteNode(reader, true);
}
}
w.Close();
string actualOutput = output.ToString();
if (actualOutput.Trim() != expectedOutput.Trim()) {
Console.WriteLine("ERROR: Test failed on line {0}", line);
Console.WriteLine("---- Expected output");
Console.WriteLine(expectedOutput);
Console.WriteLine("---- Actual output");
Console.WriteLine(actualOutput);
} else {
this.passed++;
}
}
示例12: LoadHtml
public void LoadHtml(string rawHtml)
{
if (rawHtml.StartsWith("<dsi:html"))
{
//parse and remove dsi:html tag...
string tag = rawHtml.Substring(0, rawHtml.IndexOf('>') + 1) + "</dsi:html>";
rawHtml = rawHtml.Substring(rawHtml.IndexOf('>') + 1);
rawHtml = rawHtml.Substring(0, rawHtml.Length - 11);
/*
<dsi:html
formatting = [true | false] // do we convert line-breaks to br tags?
container = [true | false] // do we render the html in a container div?
></dsi:html>
*/
SgmlReader sgml = new SgmlReader();
sgml.InputStream = new StringReader(tag);
sgml.DocType = "HTML";
sgml.Read();
if (sgml.GetAttribute("formatting") != null)
Formatting = bool.Parse(sgml.GetAttribute("formatting"));
if (sgml.GetAttribute("container") != null)
Container = bool.Parse(sgml.GetAttribute("container"));
}
this.rawHtml = rawHtml;
}
示例13: dsiTagReplacement
public string dsiTagReplacement(Match m)
{
string tagName = "dsi";
try
{
//string[] arrParts = m.Groups[1].Value.Split[" "];
//Dictionary<string, string> parts = new Dictionary<string, string>();
SgmlReader sgml = new SgmlReader();
string inStr = m.Groups[0].Value;
if (inStr.StartsWith("<dsi:link"))
inStr += "</dsi:link>";
sgml.InputStream = new StringReader(inStr);
sgml.DocType = "HTML";
sgml.Read();
tagName = sgml.Name;
string uniqueId = Guid.NewGuid().ToString("N");
#region Parse attributes
Dictionary<string, string> attributes = new Dictionary<string, string>();
while (sgml.MoveToNextAttribute())
{
attributes.Add(sgml.Name.ToLower(), sgml.Value);
}
#endregion
string typeAtt = attributes.ContainsKey("type") ? attributes["type"] : null;
string refAtt = attributes.ContainsKey("ref") ? attributes["ref"] : null;
#region Parse styles
Dictionary<string, string> style = new Dictionary<string, string>();
if (attributes.ContainsKey("style"))
{
foreach (string s in attributes["style"].Split(';'))
{
try
{
if (s.Contains(":"))
style[s.Split(':')[0].Trim()] = s.Split(':')[1].Trim();
}
catch
{
}
}
}
#endregion
#region Parse class
List<string> classes = new List<string>();
if (attributes.ContainsKey("class"))
{
foreach (string s in attributes["class"].Split(' '))
{
try
{
classes.Add(s);
}
catch
{
}
}
}
#endregion
if (tagName == "dsi:video")
{
#region dsi:video
/*
<dsi:video
type = [dsi | flv | youtube | google | metacafe | myspace | break | collegehumor | redtube | ebaumsworld | dailymotion]
ref = [dsi-photo-k | site-ref]
src = [flv-url]
width = [width] (optional)
height = [height] (optional)
nsfw = [true | false] (optional)
/>
*/
bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
if (typeAtt == "youtube")
{
#region youtube
int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 355;
//<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.youtube.com/v/" + refAtt + "&rel=1");
#endregion
}
else if (typeAtt == "metacafe")
{
#region metacafe
int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;
//<embed src="http://www.metacafe.com/fplayer/1029494/how_to_make_fire_balls.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed><br><font size = 1><a href="http://www.metacafe.com/watch/1029494/how_to_make_fire_balls/">How To Make Fire Balls</a> - <a href="http://www.metacafe.com/">The funniest videos clips are here</a></font>
return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.metacafe.com/fplayer/" + refAtt + ".swf");
#endregion
}
else if (typeAtt == "google")
//.........這裏部分代碼省略.........
示例14: GetDocReader
/// <summary>
/// Detects URLs in styles.
/// </summary>
/// <param name="baseUri">The base URI.</param>
/// <param name="attributeName">Name of the attribute.</param>
/// <param name="attributeValue">The attribute value.</param>
/// <returns></returns>
//private List<UriResourceInformation> ExtractStyleUrls(
// Uri baseUri,
// string attributeName,
// string attributeValue)
//{
// List<UriResourceInformation> result =
// new List<UriResourceInformation>();
// if (string.Compare(attributeName, @"style", true) == 0)
// {
// if (attributeValue != null &&
// attributeValue.Trim().Length > 0)
// {
// MatchCollection matchs = Regex.Matches(
// attributeValue,
// @"url\s*\(\s*([^\)\s]+)\s*\)",
// RegexOptions.Singleline | RegexOptions.IgnoreCase);
// if (matchs.Count > 0)
// {
// foreach (Match match in matchs)
// {
// if (match != null && match.Success)
// {
// string url = match.Groups[1].Value;
// UriResourceInformation ui =
// new UriResourceInformation(
// _settings.Options,
// url,
// new Uri(url, UriKind.RelativeOrAbsolute),
// baseUri,
// UriType.Resource,
// _uriInfo.AbsoluteUri,
// );
// bool isOnSameSite =
// ui.IsOnSameSite(baseUri);
// if ((isOnSameSite ||
// !_settings.Options.StayOnSite) &&
// ui.IsProcessableUri)
// {
// result.Add(ui);
// }
// }
// }
// }
// }
// }
// return result;
//}
/// <summary>
/// Gets the doc reader.
/// </summary>
/// <param name="html">The HTML.</param>
/// <param name="baseUri">The base URI.</param>
/// <returns></returns>
private static XmlReader GetDocReader(
string html,
Uri baseUri)
{
SgmlReader r = new SgmlReader();
if (baseUri != null &&
!string.IsNullOrEmpty(baseUri.ToString()))
r.SetBaseUri(baseUri.ToString());
r.DocType = @"HTML";
r.WhitespaceHandling = WhitespaceHandling.All;
r.CaseFolding = CaseFolding.None;
StringReader sr = new StringReader(html);
r.InputStream = sr;
r.Read();
return r;
}
示例15: Process
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();
}