2

rssフィードの例を次に示します。

<item>
<title>Stem cells being made from blood</title>
<description>A patient's own blood has been used to make personalised stem cells, which doctors hope can be used to treat a range of diseases.</description>
<link>http://www.bbc.co.uk/news/health-20539835#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/health-20539835</guid>
<pubDate>Fri, 30 Nov 2012 00:45:53 GMT</pubDate>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" width="66" height="49" url="http://news.bbcimg.co.uk/media/images/64469000/jpg/_64469170_c0147104-red_blood_cells%2C_artwork-spl.jpg"/>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" width="144" height="81" url="http://news.bbcimg.co.uk/media/images/64469000/jpg/_64469171_c0147104-red_blood_cells%2C_artwork-spl.jpg"/>

media:thumbnailで.jpg画像のURLを取得する必要があります。xpathまたはxqueryでそれを行うにはどうすればよいですか?誰か助けてくれませんか?ありがとうございました!

4

1 に答える 1

5

あなたのXMLが次のとおりであると仮定します。

<item>
  <title>Stem cells being made from blood</title>
  <description>A patient's own blood has been used to make personalised stem cells, which doctors hope can be used to treat a range of diseases.</description>
  <link>http://www.bbc.co.uk/news/health-20539835#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>
  <guid isPermaLink="false">http://www.bbc.co.uk/news/health-20539835</guid>
  <pubDate>Fri, 30 Nov 2012 00:45:53 GMT</pubDate>
  <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" width="66" height="49" url="http://news.bbcimg.co.uk/media/images/64469000/jpg/_64469170_c0147104-red_blood_cells%2C_artwork-spl.jpg"/>
  <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" width="144" height="81" url="http://news.bbcimg.co.uk/media/images/64469000/jpg/_64469171_c0147104-red_blood_cells%2C_artwork-spl.jpg"/>
</item>

XPath//item/media:thumbnail/@urlは必要なノードを選択します。この場合、XPath エンジンで名前空間とプレフィックスを渡す必要があります。
または、次の XPath を使用できます。

//item/*[local-name() = 'thumbnail' 
    and namespace-uri() = 'http://search.yahoo.com/mrss/']/@url
于 2012-11-30T01:54:34.890 に答える