有 Xpath 的压缩表示吗?
我正在开发一个需要使用 XPath(在 HTML 上)的项目。 (多个)XPath 在 JavaScript 内传输到客户端。由于 XPath 字符串很长,我想知道是否有更短的表示相当于 XPath?也许它的工作原理有点像霍夫曼编码,但特定于 XPath。
I am working on a project which requires working with XPath (on HTML). The (multiple) XPath is transferred to client-side inside JavaScript. Since XPath strings are long, I was wondering if there is a shorter representation which is equivalent to XPath? Perhaps one which works sort of like huffman encoding but specific to XPath.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是一些压缩算法在 JS 中的一些实现:Gzip 的 JavaScript 实现
Here are some implementations of a few compression algorithms in JS: JavaScript implementation of Gzip
如果您只是担心将 XPath 文本从服务器发送到客户端,大多数浏览器都支持 Accept-Encoding: gzip
http://developer.yahoo.net/blog/archives/2007/07/high_performanc_3.html
If you're just worried about sending the XPath text from the server to the client, most browsers support Accept-Encoding: gzip
http://developer.yahoo.net/blog/archives/2007/07/high_performanc_3.html
您可以进行从元素名称到较短别名的映射,
例如 //myelement/myotherelement[@myattribute=1234]
可以映射到 //1/2[@3=1234]
您可以将映射表一次传输到客户端,然后然后它可以翻译这些较短的 xpath 表达式。
问题是,你真的需要每个元素都有一个 xpath 吗?有共同的标准吗?您能否将标准传输给客户端,然后客户端从中创建一个 xpath?
You could do a mapping from element names to shorter alias names
like //myelement/myotherelement[@myattribute=1234]
could be mapped to //1/2[@3=1234]
You could transfer the mapping table once to the client and then it can translate these shorter xpath expressions.
A question is, do you really need an xpath for every elements? Are there common criteria? Could you transfer the criteria to the client and the client then creates an xpath from that?