1、
此例为获取Xml文件内的数据
页面内容:
2、ntAlignment="Stretch">
3、vas.Left="10" TextWrapping="Wrap" Margin="90,215,277,63" Width="49" Height="22" IsEnabled="False" FontStyle="Italic" Foreground="Blue">
4、em.Text; using System.Xml.Linq; namespace ToTestData { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); StringBuilder output = new StringBuilder(); string author = ""; int
5、 count = 0; // XmlXapResolver is the default resolver. using (XmlReader reader = XmlReader.Create("Data/book.xml"))//括号内为路径 { // Moves the reader to the root element. reader.MoveToContent(); for (int i = 0; ; i
6、) { reader.ReadToFollowing("book"); author=reader.ReadOuterXml(); if (author == "") { output.AppendLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
7、 break; } else { if (i != 0) output.AppendLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); int a = i + 1; output.AppendLine("Read
8、 the "+a+" book using ReadOuterXml..."); output.AppendLine(author); if (i == 0) { output.AppendLine("-----------------------------------------"); ShowDetail(output, au
9、thor); } count += 1; } } output.AppendLine("一共 " + count + "个节点"); } OutputTextBlock.Text = output.ToString(); } //分段显示
10、 private void ShowDetail(StringBuilder output, string author) { using (XmlReader reader = XmlReader.Create(new StringReader(author))) { reader.ReadToFollowing("book"); reader.MoveToFirstAttribute(); string genre
11、 reader.Value; reader.MoveToNextAttribute(); string genre2 = reader.Value; output.AppendLine("The genre value: " + genre); output.AppendLine("The ISBN value: " + genre2); output.AppendLine("Content of the title e
12、lement: " + GteXml(reader, "title", author)); txtTestone.Text = GteXml(reader, "price", author); btnTestone.Content = genre; } } //依据标题获取XML中内容 private static string GteXml(XmlReader reader, string name, string author) { reader.ReadToFollowing(name); author = reader.ReadInnerXml(); return author; } } } 以下为效果截屏:
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818