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