0
我在重构一个RSS,所以我决定用CasperJS写一些测试。如何在CasperJS中选择带有名称空间的标签?
其中一个RSS的元素是 “原子:链接”(“)
我想这三个码,但没有工作
test.assertExists("//atom:link", "atom:link tag exists.");
test.assertExists({
type: 'xpath',
path: "//atom:link"
}, "atom:link element exists.");
//even this...
test.assertExists({
type: 'xpath',
namespace: "xmlns:atom",
path: "//atom:link"
}, "atom:link element exists.");
的RSS代码是:
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xml:base="http://example.org/" xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>RSS Title</title>
<description>RSS description</description>
<link>http://example.org</link>
<lastBuildDate>Mon, 10 Nov 2014 11:37:02 +0000</lastBuildDate>
<language>es-ES</language>
<atom:link rel="self" href="http://example.org/rss/feed.xml"/>
<item></item>
<item></item>
</channel>
</rss>
我看到在这个页面的演示http://www.freeformatter.com/xpath-tester.html,foo:歌手可以通过:
//foo:singers
但在CasperJS似乎这不起作用...
任何人都知道如何选择这种类型的元素与命名空间?
你当然可以尝试通过解析文档中嵌入的名称空间来优化。 – 2014-11-14 17:05:28
它的工作真的很棒。复制粘贴。谢谢Artjom。 – 2014-11-17 08:12:30