Question

I'm using JTidy to clean up some XML, like this:

Tidy tidy = new Tidy();
tidy.setXmlOut(true);
tidy.setShowWarnings(false);
tidy.parse(new FileInputStream(strStrippedHTMLPath), new FileOutputStream(strXMLPath));

The problem is that it always outputs the following:

InputStream: Document content looks like HTML 4.01
5 warnings, no errors were found!

How can I prevent it from outputting anything? I tried:

tidy.setShowErrors(0);
tidy.setQuiet(true);
tidy.setErrout(null);

, as shown here, but that didn't work either.

Était-ce utile?

La solution

Well, there's always:

PrintStream oldErr = System.err();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream newErr = new PrintStream(boas);
System.setErr(newErr);
tidy.parse(...);
System.setErr(oldErr);

It would be better to use some kind of Null output stream (apparently Apache Commons has such a beast). But the gist of it is the same.

Of course, that's a bit of a hack...

Autres conseils

Instead of tidy.setErrout(null); use tidy.setErrout(new PrintWriter(new ByteArrayOutputStream())); this seems to work for me.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top