IEnumerable<string> grandChildData =
from el in StreamRootChildDoc(new StringReader(markup)) where (int)el.Attribute("Key") > 1 select (string)el.Element("GrandChild");foreach (string str in grandChildData)
{ Console.WriteLine(str); }
处理函数
static IEnumerable<XElement> StreamRootChildDoc(StringReader stringReader)
{ using (XmlReader reader = XmlReader.Create(stringReader)) { reader.MoveToContent(); // Parse the file and display each of the nodes. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Child") { XElement el = XElement.ReadFrom(reader) as XElement; if (el != null) yield return el; } break; } } } }