xml位于命名空间中时查找
static void Main(string[] args) { XElement root = XElement.Parse(@"<aw:Root xmlns:aw='http://www.efun.com'> <aw:Child1> <aw:GrandChild1>GC1 Value</aw:GrandChild1> </aw:Child1> <aw:Child2> <aw:GrandChild2>GC2 Value</aw:GrandChild2> </aw:Child2> <aw:Child3> <aw:GrandChild3>GC3 Value</aw:GrandChild3> </aw:Child3> <aw:Child4> <aw:GrandChild4>GC4 Value</aw:GrandChild4> </aw:Child4> </aw:Root>"); XNamespace aw = "http://www.efun.com"; string grandChild3 = (string) (from el in root.Descendants(aw + "GrandChild3") select el).First(); Console.WriteLine(grandChild3); }
输出结果:
GC3 Value
标签:XML,el,string,Descendants,C#,Value,查找,LINQ From: https://www.cnblogs.com/echo-efun/p/18418929