C#——LINQ to XML(使用 Descendants 方法查找单个子代)
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
------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号