我需要xpath查询的帮助来提取以下rss结果中每个条目的标题文本和缩略图网址
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'>
<entry>
<title>LiveFit Augusta - "Gym Time"</title>
<media:group>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/default.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/mqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/hqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/1.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/2.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/3.jpg'/>
</media:group>
</entry>
<entry>
<title>LiveFit Augusta - "Everyday Joes & Janes"</title>
<media:group>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/default.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/mqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/hqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/1.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/2.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/3.jpg'/>
</media:group>
</entry>
</feed>
标题
&LT; title type ='text'&gt; Dance的演变&lt; /标题&GT;
或
&LT;媒体:标题类型='普通'&gt;舞蹈的演变&lt; /媒体:标题&GT;
缩略图
<media:thumbnail
url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg' height='97' width='130'
time='00:01:30'/>
修改
这是使用
的代码Dim xmlDoc As MSXML2.DOMDocument30
Dim xmlNode As MSXML2.IXMLDOMNode
Dim xmlEntryNodes As IXMLDOMNodeList
Dim ns As String
Set xmlDoc = New DOMDocument30
ns = "xmlns:x='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'"
xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.setProperty "SelectionNamespaces", ns
If xmlDoc.loadXML(xmlText) = False Then
Exit Function
End If
Set xmlEntryNodes = xmlDoc.documentElement.selectNodes("/feed/entry")
debug.print xmlEntryNodes.Length返回0
答案 0 :(得分:1)
使用强>:
ns =“xmlns:x ='http://www.w3.org/2005/Atom'xmlns:media ='http://search.yahoo.com/mrss/'”
doc.SetProperty(“SelectionNamespaces”,ns)
然后使用像这样的XPath表达式:
/*/x:entry/x:title[. = 'Evolution of Dance']
以及:
/*/x:entry/media:group/media:thumbnail[@url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg']
详细了解SetProperty()
功能:
<强> http://msdn.microsoft.com/en-us/library/windows/desktop/ms756048(v=vs.85).aspx 强>
或者,如果您不想注册名称空间,您可能会使用不太易读的表达式,例如:
/*/*[name()='entry']/*[name()='title'][. = 'Evolution of Dance']
以及:
/*/*[name()='entry']
/*[name()='media:group']
/*[name()='media:thumbnail']
[@url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg']
答案 1 :(得分:0)
这是你在找什么?
<强>标题强>
/feed/entry/title
媒体:标题强>
/feed/entry/media:group/media:title
<强>缩略图强>
/feed/entry/media:group/media:thumbnail