开发者

Question in Chrome Extensions Sample

Can anyone explaing me this line in detail?

  // Find all the RSS link elements.
  var result = doc.evaluate(
    '//*[local-name()="rss" or local-name()="feed" or local-nam开发者_Go百科e()="RDF"]',
    doc, null, 0, null);

Best Regards, Cetin


It's doing an XPath query to find if the current document is an RSS feed by checking for the presence of certain XML elements. (Mozilla has a great run-down on XPath in JavaScript here)

Here are some examples:

Take look at the RSS Feed for this question:

<?xml version="1.0" encoding="utf-8"?>
<feed .....

It's looking for that <feed> element.

Or for example the slashdot.org main feed:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ...

It's looking for that <rdf:RDF> element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜