帮忙搞个xml读取问题.
xml 文件
<?xml version="1.0" encoding="gbk"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>bbbbbbbb</loc>
<lastmod>2013-01-15</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>aaaaaaaa</loc>
<lastmod>2013-01-15</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
</urlset>
怎么遍历url节点 获取下面 loc的值
xmldoc.DocumentElement.SelectNodes("url") 不行.
xmldoc.SelectSingleNode("urlset[@xmlns='http://www.sitemaps.org/schemas/sitemap/0.9']").ChildNodes //也不行
xmldoc.DocumentElement.SelectNodes("url"); 也不行啊...
帮忙 .net
就剩32分了 都给了.
xml?读取
------解决方案-------------------- string str = File.ReadAllText("D:\\1.xml", Encoding.Default);
var ary = Regex.Matches(str, @"(?i)(?<=<loc>).*?(?=</loc>)").OfType<Match>().Select(t => t.Value).ToArray();
------解决方案-------------------- XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\test.xml");
XmlNamespaceManager manger = new XmlNamespaceManager(xmlDoc.NameTable);
manger.AddNamespace("ns", "http://www.sitemaps.org/schemas/sitemap/0.9");
XmlNodeList urlList = xmlDoc.SelectNodes("//ns:url", manger);
------解决方案--------------------http://blog.csdn.net/happy09li/article/details/7460521