请问关于c的具体应用场景有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计457个文字,预计阅读时间需要2分钟。
我有一个Linq-to-XML查询,如果我的谷歌站点地图的urlset元素填充了属性,则可以正常工作。如果没有属性存在,则无法查询:
我有一个 Linq-2- XML查询,如果我创建的谷歌站点地图的urlset元素填充了属性,但如果没有属性存在则可以正常工作.无法查询:
<?xml version="1.0" encoding="utf-8"?> <urlset xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.sitemaps.org/schemas/sitemap/0.9 www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>www.foo.com/index.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> <url> <loc>www.foo.com/about.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> </urlset>
可以查询:
<?xml version="1.0" encoding="utf-8"?> <urlset> <url> <loc>www.foo.com/index.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> <url> <loc>www.foo.com/about.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> </urlset>
查询:
XDocument xDoc = XDocument.Load(@"C:\Test\sitemap.xml"); var sitemapUrls = (from l in xDoc.Descendants("url") select l.Element("loc").Value); foreach (var item in sitemapUrls) { Console.WriteLine(item.ToString()); }
这是什么原因?
请参阅XML中的“xmlns =”标记?您需要指定命名空间.测试代码的以下修改:XDocument xDoc = XDocument.Load(@"C:\Test\sitemap.xml"); XNamespace ns = "www.sitemaps.org/schemas/sitemap/0.9"; var sitemapUrls = (from l in xDoc.Descendants(ns + "url") select l.Element(ns + "loc").Value); foreach (var item in sitemapUrls) { Console.WriteLine(item.ToString()); }
本文共计457个文字,预计阅读时间需要2分钟。
我有一个Linq-to-XML查询,如果我的谷歌站点地图的urlset元素填充了属性,则可以正常工作。如果没有属性存在,则无法查询:
我有一个 Linq-2- XML查询,如果我创建的谷歌站点地图的urlset元素填充了属性,但如果没有属性存在则可以正常工作.无法查询:
<?xml version="1.0" encoding="utf-8"?> <urlset xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.sitemaps.org/schemas/sitemap/0.9 www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>www.foo.com/index.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> <url> <loc>www.foo.com/about.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> </urlset>
可以查询:
<?xml version="1.0" encoding="utf-8"?> <urlset> <url> <loc>www.foo.com/index.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> <url> <loc>www.foo.com/about.htm</loc> <lastmod>2010-05-11</lastmod> <changefreq>monthly</changefreq> <priority>1.0</priority> </url> </urlset>
查询:
XDocument xDoc = XDocument.Load(@"C:\Test\sitemap.xml"); var sitemapUrls = (from l in xDoc.Descendants("url") select l.Element("loc").Value); foreach (var item in sitemapUrls) { Console.WriteLine(item.ToString()); }
这是什么原因?
请参阅XML中的“xmlns =”标记?您需要指定命名空间.测试代码的以下修改:XDocument xDoc = XDocument.Load(@"C:\Test\sitemap.xml"); XNamespace ns = "www.sitemaps.org/schemas/sitemap/0.9"; var sitemapUrls = (from l in xDoc.Descendants(ns + "url") select l.Element(ns + "loc").Value); foreach (var item in sitemapUrls) { Console.WriteLine(item.ToString()); }

