views:

344

answers:

5

I have TONS of XML Parsing Error: EntityRef: expecting ';' errors on my page only because of the incorrect use ampersands in links by the developer.

Instead of asking him to use & instead of &, how can I replace those after page load using jQuery?

Edit: Ah right, validators read the source so it won't work. Is there any other way to filter HTML and clear out silly errors like these?

Thanks!

A: 

jQuery will not help solving validation errors. In fact, validators don't even run JavaScript.

Kobi
Validators read source, ah right!
Nimbuz
A: 

You will not be able to correct parse errors after the page has already been loaded and parsed. The only correct solution is to do the replacement on the server side.

David
+1  A: 

Replacing the textual content of a page will have absolutely no effect on your validation results, as a validator does not execute scripts. It will still see the original content of the fetched document.

If you still want to do it for reasons other than validation, you could try something like this plugin.

zombat
A: 

Even if you could fix them in jQuery, the page is already processed by that point and the errors would still be thrown. You would be better off doing a global search for & and manually replacing them.

Doug Neiner
Nimbuz
Thats why I said `manually` replacing them. :) I am sure there is a regex like that out there. Without knowing your editor and its restrictions I wanted to communicate the general idea of fixing it on the server.
Doug Neiner
+2  A: 

This ain't going to work in Javascript, you really need to solve this at the server side.

As per the comments, you're using JSP. You can use the JSTL (just drop jstl-1.2.jar in /WEB-INF/lib) <c:out> and <c:url> tags for this.

The <c:out> by default escapes HTML entities <, >, &, " and '. The <c:url> can be used in combination with <c:param> which by default encodes query parameters.

BalusC