读取XML数据的问题
<?xml version="1.0" encoding="utf-8" ?><Items> <MenuItem Text="分类"> <MenuItem Text="瓷器" IsEnabled="false"/> <MenuItem Text="青铜器" IsEnabled="false"/> <MenuItem Text="玉器"/> <MenuItem Text="陶器"/> </MenuItem> <MenuItem Text="年代"> <MenuItem Text="西周"/> <MenuItem Text="汉代"/> <MenuItem Text="唐代"/> <MenuItem Text="宋代" IsEnabled="false"/> <MenuItem Text="元代"/> <MenuItem Text="明代"/> <MenuItem Text="清代" IsEnabled="false"/> </MenuItem></Items>
public class MenuItem { private bool isEnabled = true; private string text; private List<MenuItem> children; public string Text { get { return this.text; } set { this.text = value; } } public bool IsEnabled { get { return this.isEnabled; } set { this.isEnabled = value; } } public List<MenuItem> Children { get { return this.children; } set { this.children = value; } } }
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { List<MenuItem> mi = new List<MenuItem>(); MenuItem CurrentItem = null; XmlReader reader = XmlReader.Create(e.Result); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "MenuItem") { CurrentItem = new MenuItem(); ................ } } }