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.
Asked
Active
Viewed 303 times
1
-
In Which language are you trying to do that? – apaderno Dec 20 '09 at 07:26
-
PHP but I believe the code will need to be both at client side and server side. – Paras Chopra Dec 20 '09 at 11:05
3 Answers
1
Here are some implementations of a few compression algorithms in JS: JavaScript implementation of Gzip

Community
- 1
- 1

Ben McCann
- 18,548
- 25
- 83
- 101
1
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

Annie
- 6,621
- 22
- 27
-
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 Dec 20 '09 at 11:07
0
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
- 28,510
- 21
- 92
- 151