Hi,
I am a newbie using JTidy to clean up some very messy HTML to produce XHTML. I am having trouble getting JTidy to clean up the script code.
Please could someone tell me how to get JTidy to wrap JavaScript code with CDATA tags so that:
<script language="javascript" type="text/javascript">...XXX...</script>
becomes:
<script language="javascript" type="text/javascript"> <![CDATA[...XXX...]]></script>
My code is below (note that I am using 'tidy.setWrapScriptlets(true)' ):
public class JTidyTest {
public static void main(String[] args) {
out.println("---=== JTidy ===---");
if(args.length < 1) {
System.err.println("Usage: java JTidyTest input_filename");
System.exit(1);
}
Tidy tidy = new Tidy(); // obtain a new Tidy instance
tidy.setXHTML(true); // set desired config options using tidy setters
// (equivalent to command line options)
tidy.setOnlyErrors(true);
tidy.setShowWarnings(false);
tidy.setQuiet(true);
tidy.setWrapScriptlets(true);
tidy.setWrapSection(true);
tidy.setTidyMark(true);
tidy.setAltText("alt_text");
try {
FileInputStream in = new FileInputStream(new File(args[0]));
FileOutputStream oot = new FileOutputStream(new File("output.xhtml"));
Document doc = tidy.parseDOM(in, System.out); // run tidy, providing an input and output stream
out.println(doc);
tidy.pprint(doc,oot);
out.println("Parse complete.");
}
catch(IOException e) { ErrorHandler.error(e); }
out.println("---=== Done ===---");
}
}
Thanks in advance,
Tom
|