|
Re: Parsing HTML: msg#00078java.enhydra.xmlc
Here is an example of creating a Document from a file....of course this example assumes the file is valid XML.... DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); dbfactory.setNamespaceAware(true); DocumentBuilder dbuilder = dbfactory.newDocumentBuilder(); InputStream is = context.getResourceAsStream("/WEB-INF/snippets/header.xml"); Document doc = dbuilder.parse(is); Note that the "context" is a ServletContext and the way we are loading things makes it so you don't have to provide an absolute file path to the file. This makes things very portable as there is no extra configuration required and it is platform agnostic. Plus, it can load the file even if the context is being deployed directly from a .war file where you wouldn't have file IO access within your webapp. I'm not sure how to modify this example to load a valid HTML4 file? If you use this example, your file will have to be XHTML valid...meaning that all tags which are opened must then be closed. If you come up with a way to do this with a non-XML-compliant HTML file, I'd appreciate it if you posted the example back to the list. later, Jake At 12:37 PM 3/24/2003 -0600, you wrote: That's pretty much what I want to do. I guess my question now is how do I create a document from the file? I know how to compile a document, but I don't know how to load a HTML document into a DOM tree at runtime.
|
|
| <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 |