xml 中的冒号 读取问题的解决
程序员文章站
2023-11-18 16:49:52
参考文章:http://chs.gotdotnet.com/quickstart/howto/doc/xml/xmlnamespace.aspx 偶的源码: &...
参考文章: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 += "<br>相册url:" + xn.selectsinglenode("link").innertext;//相册url
outstr += "<br>相册图片:<img src='" + xn.selectsinglenode("image/url").innertext + "' />";//相册首页图片
//outstr += "<br><img src='" + xn.selectnodes("item")[0].selectsinglenode("enclosure").value + "'>";
system.xml.xmlnodelist xnl = xn.selectnodes("item");
outstr += "<br>相册图片数:" + 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 += "<br>media:title:"+nodelist[0].selectsinglenode("media:title",nsmanager).attributes["type"].innertext;
// for(int i=0;i<xnl.count;i++)
// {
// outstr += "<br> <img src='"+xnl[i].selectsinglenode("enclosure").attributes["url"].innertext+"' />";
// }
}
当时看到了。。gg的xml里面有冒号,就卡卡解决了。。
付上xml片段
- <media:group>
<media:title type="plain">02.jpg</media:title>
<media:description type="plain" />
<media:keywords />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s72/02.jpg" height="48" width="72" />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s144/02.jpg" height="96" width="144" />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s288/02.jpg" height="192" width="288" />
<media:content url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/02.jpg" height="400" width="600" type="image/jpeg" medium="image" />
<media:credit>成刚</media:credit>
</media:group>
xml地址:http://picasaweb.google.com/pengpengsay/lnfxfk
偶的源码:
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 += "<br>相册url:" + xn.selectsinglenode("link").innertext;//相册url
outstr += "<br>相册图片:<img src='" + xn.selectsinglenode("image/url").innertext + "' />";//相册首页图片
//outstr += "<br><img src='" + xn.selectnodes("item")[0].selectsinglenode("enclosure").value + "'>";
system.xml.xmlnodelist xnl = xn.selectnodes("item");
outstr += "<br>相册图片数:" + 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 += "<br>media:title:"+nodelist[0].selectsinglenode("media:title",nsmanager).attributes["type"].innertext;
// for(int i=0;i<xnl.count;i++)
// {
// outstr += "<br> <img src='"+xnl[i].selectsinglenode("enclosure").attributes["url"].innertext+"' />";
// }
}
当时看到了。。gg的xml里面有冒号,就卡卡解决了。。
付上xml片段
- <media:group>
<media:title type="plain">02.jpg</media:title>
<media:description type="plain" />
<media:keywords />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s72/02.jpg" height="48" width="72" />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s144/02.jpg" height="96" width="144" />
<media:thumbnail url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/s288/02.jpg" height="192" width="288" />
<media:content url="http://lh3.google.com/pengpengsay/r3c96dqjbui/aaaaaaaaaeo/j3cspo0ig7o/02.jpg" height="400" width="600" type="image/jpeg" medium="image" />
<media:credit>成刚</media:credit>
</media:group>
xml地址:http://picasaweb.google.com/pengpengsay/lnfxfk
上一篇: c# 数据库的 sql 参数封装类的编写
下一篇: JS 实现计算器详解及实例代码(一)
推荐阅读
-
Python中循环后使用list.append()数据被覆盖问题的解决
-
Python2.x中str与unicode相关问题的解决方法
-
java中tomcat的80端口被占用问题解决
-
解决Flask读取mysql数据库的中文乱码问题
-
mysqlreport显示Com_中change_db占用比例高的问题的解决方法
-
完美解决在oj中Python的循环输入问题
-
php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
-
PHP中source #N问题的解决方法
-
使用jQuery快速解决input中placeholder值在ie中无法支持的问题
-
Win2008 R2中IIS7.5配置完网站权限不足问题的解决方法