服务器端 CSS 选择器

2022-01-09 00:00:00 css-selectors html coldfusion java

我正在创建一个工具,它将检查动态生成的 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

相关文章