views:

47

answers:

3

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.

+1  A: 

Here are some implementations of a few compression algorithms in JS: http://stackoverflow.com/questions/294297/javascript-implementation-of-gzip

Ben McCann
+1  A: 

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%5Fperformanc%5F3.html

Annie
The output is GZip but I also worry about storing XPath on the server as (because of nature of my problem) there could be a lot of Xpath representations per page. Sort of like Xpath for every element on the page.
Paras Chopra
A: 

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?

codymanix