本文整理汇总了C#中System.Xml.XmlNodeReader.ReadToDescendant方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeReader.ReadToDescendant方法的具体用法?C# XmlNodeReader.ReadToDescendant怎么用?C# XmlNodeReader.ReadToDescendant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.ReadToDescendant方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialise
private static Projects Deserialise(XmlDocument xmlDoc)
{
var nodeReader = new XmlNodeReader(xmlDoc);
nodeReader.ReadToDescendant("Projects");
var result = Serialiser.Deserialize(nodeReader);
return (Projects)result;
}
示例2: 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);
}