• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Easy way to create and manipulate XPath strings in JavaScript?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm looking for a package which makes it easier to create XPath strings in JavaScript. I will need to have JavaScript create XPath strings to be passed to a Java program which will use the XPath strings to access DOM elements. The developer who is responsible for our JavaScript code doesn't want to use normal XPath strings since they will contain so many single quotes whch will need to be escaped. But I'm not amenable to using the home-grown XPath approach and would rather stick with using standard XPath strings. So I'm hoping to find a package (an encoder of some sort? a JavaScript XPath object?) that he can use which will make it easier to construct these XPath strings without making it too difficult or ugly with lots of escape characters, etc.

Thanks in advance for any suggestions.


--James
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is one trick I used to avoid character esaping - using a textarea.
let say JSP has the following:
<textarea id='var'><%=someVariable%></textarea>
than your javasrcipt will have an access to that value using
document.getElementById('var').value
, and no escaping has to be done there. You can hide this textarea from user using CSS.
The only problem you can run into is if this variable contains "</textarea>" in it, but what are the chances? If you really worried about that you can solve that on java side.

If you need more help, please provide more info on what are you trying to do, may be show some java/javascript code examples.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic