2

次のように、JTidy を使用して一部の XML をクリーンアップしています。

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

問題は、常に次のように出力されることです。

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

何かを出力しないようにするにはどうすればよいですか? 私は試した:

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

、ここに示すように、しかしそれもうまくいきませんでした。

4

2 に答える 2

1

まあ、常にあります:

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

ある種の Null 出力ストリームを使用することをお勧めします (どうやら Apache Commons にはそのような野獣がいます)。しかし、その本質は同じです。

もちろん、それはちょっとしたハックです...

于 2013-02-03T21:25:24.000 に答える