Is there a compressed representation of Xpath?
I am working on a project which requires working with XPath (on HTML). The (multiple) XPath is t开发者_如何学编程ransferred 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.
Here are some implementations of a few compression algorithms in JS: JavaScript implementation of Gzip
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
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?
精彩评论