当前位置: 编程技术>.net/c#/asp.net
xml 中的冒号 读取问题的解决
来源: 互联网 发布时间:2014-10-13
本文导语: 参考文章:http://chs.gotdotnet.com/quickstart/howto/doc/Xml/XmlNameSpace.aspx 偶的源码: public void bindXml(string xmlUrl) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load( Syst...
参考文章:http://chs.gotdotnet.com/quickstart/howto/doc/Xml/XmlNameSpace.aspx
偶的源码:
public void bindXml(string xmlUrl)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load( System.AppDomain.CurrentDomain.BaseDirectory+"kkjj.xml");
//doc.Load(xmlUrl);
doc.SelectNodes("/rss/channel");
System.Xml.XmlNode root = doc.DocumentElement;
System.Xml.XmlNode xn = root.SelectSingleNode("/rss/channel");
outStr += "相册名称:" + xn.SelectSingleNode("title").InnerText;//相册名称
outStr += "
相册url:" + xn.SelectSingleNode("link").InnerText;//相册url
outStr += "
相册图片:";//相册首页图片
//outStr += "
";
System.Xml.XmlNodeList xnl = xn.SelectNodes("item");
outStr += "
相册图片数:" + xnl.Count.ToString() + "张";
System.Xml.XmlNamespaceManager nsmanager = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmanager.AddNamespace("media", "http://search.yahoo.com/mrss/");
// 创建包含 XPATH 表达式的字符串以进行计算。
string exprString = String.Format("// {0}:group", "media");
System.Xml.XmlNodeList nodelist = doc.SelectNodes(exprString, nsmanager);
outStr += "
media:title:"+nodelist[0].SelectSingleNode("media:title",nsmanager).Attributes["type"].InnerText;
// for(int i=0;i
偶的源码:
public void bindXml(string xmlUrl)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load( System.AppDomain.CurrentDomain.BaseDirectory+"kkjj.xml");
//doc.Load(xmlUrl);
doc.SelectNodes("/rss/channel");
System.Xml.XmlNode root = doc.DocumentElement;
System.Xml.XmlNode xn = root.SelectSingleNode("/rss/channel");
outStr += "相册名称:" + xn.SelectSingleNode("title").InnerText;//相册名称
outStr += "
相册url:" + xn.SelectSingleNode("link").InnerText;//相册url
outStr += "
相册图片:";//相册首页图片
//outStr += "
";
System.Xml.XmlNodeList xnl = xn.SelectNodes("item");
outStr += "
相册图片数:" + xnl.Count.ToString() + "张";
System.Xml.XmlNamespaceManager nsmanager = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmanager.AddNamespace("media", "http://search.yahoo.com/mrss/");
// 创建包含 XPATH 表达式的字符串以进行计算。
string exprString = String.Format("// {0}:group", "media");
System.Xml.XmlNodeList nodelist = doc.SelectNodes(exprString, nsmanager);
outStr += "
media:title:"+nodelist[0].SelectSingleNode("media:title",nsmanager).Attributes["type"].InnerText;
// for(int i=0;i