xml 中的冒号 读取问题的解决
程序员文章站
2022-06-21 08:15:11
参考文章: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