問題描述
我正在創建一個工具,它將檢查動態生成的 XHTML 并根據預期內容對其進行驗證.
I am creating a tool that will check dynamically generated XHTML and validate it against expected contents.
我需要確認結構正確且特定屬性存在/匹配.可能還有其他我不感興趣的屬性,所以直接字符串比較是不合適的.
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.
驗證這一點的一種方法是使用 XPath,我已經實現了這一點,但我還想要一些不那么冗長的東西 - 我希望能夠使用 CSS 選擇器,就像我可以使用 jQuery 一樣,但在服務器上 - 在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 選擇器?
推薦答案
我剛剛發布了一個開源項目,它是 Java 中的 W3C CSS Selectors Level 3 實現.請試一試.我一直在尋找同樣的東西,并決定實現我自己的引擎.它的靈感來自 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
這篇關于服務器端 CSS 選擇器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!