本文整理匯總了C#中System.Xml.XmlNodeReader.ReadToFollowing方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlNodeReader.ReadToFollowing方法的具體用法?C# XmlNodeReader.ReadToFollowing怎麽用?C# XmlNodeReader.ReadToFollowing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.ReadToFollowing方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
var artists = new List<string>();
var albums = new List<string>();
var catalogFilePath = "../../../../catalog.xml";
XmlDocument doc = new XmlDocument();
doc.Load(catalogFilePath);
using (XmlNodeReader reader = new XmlNodeReader(doc))
{
reader.MoveToContent();
reader.ReadToDescendant("album");
while (reader.Read())
{
var albumName = reader.ReadInnerXml();
albums.Add(albumName);
var artist = reader.ReadInnerXml();
artists.Add(artist);
reader.ReadToFollowing("album");
}
}
string albumFilePath = "../../album.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlTextWriter writer = new XmlTextWriter(albumFilePath, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
for (int i = 0, len = artists.Count; i < len; i++)
{
WriteAlbum(writer, albums[i], artists[i]);
}
writer.WriteEndDocument();
}
Console.WriteLine("Document {0} created.", albumFilePath);
}