本文整理汇总了C#中XmlTextReader.ReadToEnd方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadToEnd方法的具体用法?C# XmlTextReader.ReadToEnd怎么用?C# XmlTextReader.ReadToEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadToEnd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: parseXML
public void parseXML(string strPath)
{
try {
XmlTextReader reader = new XmlTextReader (strPath);
reader.Read ();
Console.WriteLine ("--- Dateianfang ---");
Console.WriteLine (reader.ReadToEnd ());
Console.WriteLine ("--- Dateiende -----");
Console.WriteLine (reader.NodeType); // It prints "XmlDeclaration"
reader.MoveToContent ();
Console.WriteLine (reader.NodeType); // It prints "Element"
Console.WriteLine (reader.Name); // "rss"
Console.WriteLine (reader.GetAttribute ("version")); // Maybe "0.92"
// proceed content until we reach "item" element
while (!reader.EOF && reader.Name != "item")
reader.Read ();
reader.Read (); // Move from "item" to "title"
while (reader.NodeType == XmlNodeType.Whitespace)
reader.Read ();
Console.WriteLine ("Title : " + reader.ReadString ());
reader.Read (); // from "</title>" to whitespace
reader.Read (); // from whitespace to <link>
Console.WriteLine ("Link : " + reader.ReadString ());
reader.Read (); // from "</link>" to whitespace
reader.Read (); // from whitespace to <pubDate>
Console.WriteLine ("Date : " + reader.ReadString ());
reader.Read (); // from "</pubDate>" to whitespace
reader.Read (); // from whitespace to <description>
Console.WriteLine ("Description : " + reader.ReadString ());
}
// Datei nicht gefunden
catch (FileNotFoundException ex) {
Console.WriteLine (ex.Message);
}
// Verzeichnis existiert nicht
catch (DirectoryNotFoundException ex) {
Console.WriteLine (ex.Message);
}
// Pfadangabe war 'null'
catch (ArgumentNullException ex) {
Console.WriteLine (ex.Message);
}
// Pfadangabe war leer ("")
catch (ArgumentException ex) {
Console.WriteLine (ex.Message);
}
// allgemeine Exception
catch (Exception ex) {
Console.WriteLine (ex.Message);
}
}