using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace 查找XML
{
class Program
{
static void Main(string[] args)
{
XDocument xdoc = XDocument.Load("person.xml");
List<XElement> list = new List<XElement>();
SearchElementsZhao(xdoc.Root, list);
}
public static void SearchElementsZhao(XElement ele, List<XElement> list)
{
foreach (XElement item in ele.Elements())
{
if (item.Name.LocalName == "name")
{
if (item.Value == "赵子龙")
{
list.Add(item.Parent);
}
}
// 如果item里面还有子节点就递归
SearchElementsZhao(item, list);
}
}
}
}