Is there a tool or library that can take HTML and realign the URLs contained within that HTML so that they work properly in a new context?
For instance, imagine 1) http://wherever/one/homepage.htm uses Ajax to retrieve HTML from / two/somepage.htm 2) http://wherever/two/somepage.htm has some content like: <a href="http://someplaceelse/abc.htm">ABC</a> <a href="/def.htm">DEF</a> <a href="ghi/page.htm">GHI</a> <a href="jkl.htm">JKL</a> <img src="http://someplaceelse/MNO.gif"> <img src="/PQR/image.gif"> <img src="STU/image.gif"> <img src="VWX.gif"> 3) To drop somepage.htm's content into the homepage.htm from step 1, the urls must all be refactored to take into account the new location. ABC, DEF, MNO and PQR can be left as they are. GHI, JKL, STU, and VWX must all be modified to take into account the location of the page which was retrieved, or they will be invalid links or unloaded images. It would be handy to drop the content into the element and then get all img and anchor elements and fix them, but it is too late by that time because the browser has already expanded the link or src value. Doing some string search and replacement is feasible but I am wondering what gotchas I could miss, especially with messy or malformed HTML code. Is there anything out there that is built (well) to address this? thanks! Joe