Re: Using Java to produce HTML like a php script




<spudtheimpaler@xxxxxxxxx> wrote in message
news:1137698931.868104.189400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I am a university student using a program that requires updated xml
> from a webpage (well, a webserver). Now i know this can be done with
> php and apparently quite easily but I would really rather do this with
> Java (as the program that will be manipulating the information to be
> described is going to be in java if possible).
>
> So my question is are there any tools / apis that are good at
> outputting xml in a web page/server setting for java?
>
>
Sorry, your question and your subject seem to be at odds with one another.

What format are you reading and what format are you writing?

If you're simply looking to generate HTML within a Java program, as your
subject suggests, here is a simple Java class that does exactly that:

================================================================
public class MyHtmlWriter {

public MyHtmlWriter() {
}

/**
* Writes the file.
*
* @param outfile the name of the file that will be written by this
class.
*/
public void writeFile(String outfile) {

/* Identify the output file. */
String strOutfile = OUTPUT_FILE_PATH + "my.html";

/* Delete the old version of the output file. */
File outfile = new File(strOutfile);
outfile.delete();

/* Open the output file. */
FileOutputStream fos = null;
OutputStreamWriter osw = null;
PrintWriter pw = null;

try {
fos = new FileOutputStream(strOutfile, true);
} catch (FileNotFoundException excp) {
System.err.println("FileNotFoundException on file " + strOutfile
+ ". Error: " + excp);
excp.printStackTrace();
return;
}

osw = new OutputStreamWriter(fos);
pw = new PrintWriter(new BufferedWriter(osw), true);


printWriter.println("<html>");
printWriter.println("<body>");
printWriter.println("<p>This is my document.</p>");
printWriter.println("</body>");
printWriter.println("</html>");

printWriter.flush(); /* write out any unwritten lines */
printWriter.close(); /* close the file */

/* Tell the user where to find the report. */
System.out.println("The output was written to file " + outfile +
".");

return;
}
}

================================================================

If that is not what you're trying to do, please clarify your requirements.

Java is certainly capable of reading and writing XML if that is a concern
for you.

It is also possible to use something called XSL to convert XML documents to
HTML. XSL could involve Java but doesn't have to; I've got some XML docs
(log files) that I convert to HTML without involving Java at all: there is
an XSL file that describes how the XML is supposed to be converted to HTML,
then I run a trivial script to do the actual conversion, supplying the name
of the XML file and the name of the XSL file. The XSL is capable of some
reasonable smarts so it can choose particular records and ignore others,
format some records differently than others, etc.

It's probably not a good idea to use Java for everything, just because it is
possible. You can use a wrench to hammer something but sometimes a hammer is
a better choice. :-)

Rhino


.



Relevant Pages

  • Re: onclick - reassign new function with parameters after displaye
    ... It creates an HTML document which looks and acts correctly. ... The orginal XSL is creating a record that shows data from two different ... The form reads in those global variables. ... XML Node that forms the context of your little XSL. ...
    (microsoft.public.scripting.jscript)
  • Re: onclick - reassign new function with parameters after displaye
    ... As far as XML data, it is not on the client side, and my limted ... as global parameter the info I need to get correct record from HTML, ... needed into XSL proscessing. ... The form reads in those global variables. ...
    (microsoft.public.scripting.jscript)
  • Printing HTML from memory (no user interaction)
    ... application in C# that converts text from XML with an XSL to a HTML ... The string writer contains the information I wanted as HTML. ... The real problem is that I cannot parse the ...
    (microsoft.public.dotnet.academic)
  • Printing HTML from memory (no user interaction)
    ... application in C# that converts text from XML with an XSL to a HTML ... The string writer contains the information I wanted as HTML. ... The real problem is that I cannot parse the ...
    (microsoft.public.dotnet.csharp.general)
  • Printing HTML from memory (no user interaction)
    ... application in C# that converts text from XML with an XSL to a HTML ... The string writer contains the information I wanted as HTML. ... The real problem is that I cannot parse the ...
    (microsoft.public.dotnet.general)