[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
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(ns + "CarForSale") select d;
var cars2 = from d in doc.Descendants() where d.Name.LocalName == "CarForSale" select d;
相关文章推荐
- Read XML file easily with LINQ to XML
- hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点
- LINQ to XML
- LINQ TO XML(查询)
- LINQ to SQL with NOLOCK
- Parser exception for xx/AndroidManifest.xml: The reference to entity "z" must end with the ';' delim
- linq to xml
- XML遍历(LINQ TO XML的魅力)
- Linq to xml demo
- Convert XML to Object using LINQ
- Linq To Xml
- LINQ to XML
- LINQ to XML
- Linq To Xml (增,删,改,查)
- LINQ TO XML 基本操作
- Linq to XML增删改查
- [Exception]SEVERE: Failed to set the internal configuration of the OC4J JMS Server with: XMLJMSServerConfig
- 24.C#LINQ TO XML(十二章12.3)
- LINQ体验(二)LINQ to XML
- 使用Linq to XML创建保存XML