問題描述
我正在創(chuàng)建一個(gè)工具,它將檢查動態(tài)生成的 XHTML 并根據(jù)預(yù)期內(nèi)容對其進(jìn)行驗(yàn)證.
I am creating a tool that will check dynamically generated XHTML and validate it against expected contents.
我需要確認(rèn)結(jié)構(gòu)正確且特定屬性存在/匹配.可能還有其他我不感興趣的屬性,所以直接字符串比較是不合適的.
I need to confirm the structure is correct and that specific attributes exist/match. There may be other attributes which I'm not interested in, so a direct string comparison is not suitable.
驗(yàn)證這一點(diǎn)的一種方法是使用 XPath,我已經(jīng)實(shí)現(xiàn)了這一點(diǎn),但我還想要一些不那么冗長的東西 - 我希望能夠使用 CSS 選擇器,就像我可以使用 jQuery 一樣,但在服務(wù)器上 - 在CFML 代碼 - 而不是在客戶端上.
One way of validating this is with XPath, and I have implemented this already, but I would also like something less verbose - I want to be able to use CSS Selectors, like I can with jQuery, but on the server - within CFML code - as opposed to on the client.
是否有 CFML 或 Java 庫允許我針對 XHTML 字符串使用 CSS 選擇器?
推薦答案
我剛剛發(fā)布了一個(gè)開源項(xiàng)目,它是 Java 中的 W3C CSS Selectors Level 3 實(shí)現(xiàn).請?jiān)囈辉?我一直在尋找同樣的東西,并決定實(shí)現(xiàn)我自己的引擎.它的靈感來自 WebKit 等中的代碼.
I've just released an open source project which is a W3C CSS Selectors Level 3 implementation in Java. Please give it a try. I was looking for the same thing and decided to implement my own engine. It's inspired by the code in WebKit etc.
http://github.com/chrsan/css-selectors/tree
這篇關(guān)于服務(wù)器端 CSS 選擇器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!