您的位置:首页 > 其它

[Tips and Tricks] LINQ to XML with xmlns

2010-06-29 16:36 417 查看
If your XML file has xmlns, you may be run into problem when get some XML data with LINQ.

How to fix this?

1. prepend the namespace

XNamespace ns = doc.Root.Name.Namespace;
var cars2 = from d in doc.Descendants(ns + "CarForSale") select d;

2. search by local name:

var cars2 = from d in doc.Descendants() 
            where d.Name.LocalName == "CarForSale" 
            select d;


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: