|
Re: Parsing HTML: msg#00090java.enhydra.xmlc
On Thursday, Mar 27, 2003, at 02:53 Asia/Shanghai, Ben Sinclair wrote: Actually, now that I think about it further, this doesn't really work for me. I have one servlet that can be used by multiple "sponsors." Each time you pass a different referrer ID to the servlet, it loads a different header and footer, so I couldn't recompile each time. You don't need to compile every time. Let's assume that you have the following layout for HTML: /Master.html /sponsor1/Header.html /sponsro1/Footer.html /sponsor2/Header.html /sponsor2/Footer.html Assuming the Header section is tagged with ID 'Header' in Master.html and all Header.html and Footer is tagged with ID 'Footer'. In your codes: String sponsorid = request.getParameter("sponsor"); Document master = xmlcContext.loadFile("Master.html"); Document header = xmlcContext.loadFile("/" + sponsorid + "/Header.html"); Document footer = xmlcContext.loadFile("/" + sponsorid + "/Footer.html"); Element headerElm = header.getElementById("Header"); Element footerElm = footer.getElementById("Footer"); Element hElm = master.importNode(headerElm, true); Element fElm master.importNode(footerElm, true); mater.getElementById("Header").getParentNode().replaceChild(hElm, mater.getElementById("Header")); mater.getElementById("Footer").getParentNode().replaceChild(fElm, mater.getElementById("Footer")); In this codes, the parsing only took place when the document is first loaded and after each change to the html. Otherwise, the Document is retrieved from the Factory's cache. By the way, the Header/Footer html has to be full HTML with <html>/<header>/<body> but it shouldn't be a problem. David The way I'm doing it now works just fine for the browsers I've tested, even though the HTML wouldn't pass a validator. The only problem with my method is that it tends to chop off the last part of my footer file when I load it like this:
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Parsing HTML, Ben Sinclair |
|---|---|
| Next by Date: | Re: Parsing HTML, Ben Sinclair |
| Previous by Thread: | Re: Parsing HTML, Ben Sinclair |
| Next by Thread: | Re: Parsing HTML, Ben Sinclair |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |