in my GWT application, on the client side I have a string containing html. Is there a good way to go about parsing that and finding specific html tags within it and returning the id’s of those tags?
Any help would be much appreciated, thanks!
Advertisement
Answer
You could attach your HTML string to the DOM – using Element.setInnerHTML(yourString). That way you’re using the browser’s parser. Attaching it to an invisible element or an invisible iframe should hide whats happening from the user.
For the querying you can use GWT’s DOM functions if you want to stick with plain GWT. Using JavaScript directly or any JavaScript library like jQuery are also options. GWT query might also be an option, but I haven’t used that yet.
UPDATE:
This approach can be abused by XSS (cross site scripting) attacks – so you must either trust or sanitize the HTML string.