我有一个这样的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<KWS>
<KW>
<KWNAME>"make money online youtube video"</KWNAME>
<GSC>318,000</GSC>
<YSC>821</YSC>
<TOP10>6</TOP10>
<TOP100>61</TOP100>
<SEARCH-US-C>0</SEARCH-US-C>
<NOTE>
</NOTE>
<YTLINKS>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=Dh5vptODX-M</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=YtjvHX6VfcY</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=WDfJoDCdvyw</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=yRUEffXbokw</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=YYsqgs5ve78</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=7WaG3D-tSrs</LINK>
</YT-LINK>
</YTLINKS>
</KW>
<KW>
<KWNAME>"linkin park video youtube"</KWNAME>
<GSC>130,000</GSC>
<YSC>4,300</YSC>
<TOP10>7</TOP10>
<TOP100>69</TOP100>
<SEARCH-US-C>0</SEARCH-US-C>
<NOTE>
</NOTE>
<YTLINKS>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=ij34hCOMiIU</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=mTMl5dRw8WI</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=b-JehygMcJ8</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=b2dmMxnUosc</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=hZ62r3Q6ohA</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=dREoOlTeYs4</LINK>
</YT-LINK>
<YT-LINK>
<LINK>http://www.youtube.com/watch?v=42xL8MG3xfQ</LINK>
</YT-LINK>
</YTLINKS>
</KW>
</KWS>
我的 C# 代码用于获取 YT-LINK 中的每个 LINK
XmlDocument xml = new XmlDocument();
xml.Load(file);
XmlNodeList nodes = xml.SelectNodes("//KW");
foreach (XmlNode node in nodes)
{
KWDATA k = new KWDATA();
k.KEYWORD = node.SelectSingleNode("KWNAME").InnerText;
k.GSC = node.SelectSingleNode("GSC").InnerText;
k.YTC = node.SelectSingleNode("YSC").InnerText;
k.N_VIDEOS_TOP_10 = node.SelectSingleNode("TOP10").InnerText;
k.N_VIDEOS_TOP_100 = node.SelectSingleNode("TOP100").InnerText;
k.N_OF_KW_SEARCH_IN_GOOGLE = node.SelectSingleNode("SEARCH-US-C").InnerText;
List<string> YT_LINKS = new List<string>();
foreach (XmlNode node2 in node.SelectNodes("YTLINKS")) // <-- i know something is wrong here
{
MessageBox.Show(node2.SelectSingleNode("YT-LINK").InnerText);
YT_LINKS.Add(node2.SelectSingleNode("YT-LINK").InnerText);
}
k.YTLINKS = YT_LINKS;
但我只获得每个条目的第一个链接,例如:
http://www.youtube.com/watch?v=Dh5vptODX-M
http://www.youtube.com/watch?v=ij34hCOMiIU
只有,其余的将不会被检索。