有谁知道哪里出错?或者是将视频名称转换为字符串的更好方法?XmlNodelist中的XmlNode
string text = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><entry><title>VIDEO NAME</title></entry></feed>";
string xpath = "feed/entry";
XmlDocument xml = new XmlDocument();
xml.LoadXml(text);
XmlNodeList nodes = xml.SelectNodes(xpath);
foreach (XmlNode node in nodes)
{
string title = node["title"].InnerText;
MessageBox.Show(title);
}
XML
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<entry>
<title>VIDEO NAME</title>
</entry>
</feed>
您可以在标题使用XPath =饲料/入境后右转/标题并在迭代中跳过查找,但你有什么问题? – dkackman 2013-03-09 13:40:21
不明白你的意思。如果我运行代码,它不显示消息框。 – Bullman 2013-03-09 13:50:23
该部分在您的问题中不清楚。如果你对你期望的代码做什么以及它在做什么非常具体,它有助于产生答案 – dkackman 2013-03-09 13:51:48