XOM xml ライブラリを使用してファイルを解析するときに、DTD 宣言を無視するにはどうすればよいですか。私のファイルには次の行があります:
<?xml version="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI//NCBI BlastOutput/EN" "NCBI_BlastOutput.dtd">
//rest of stuff here
そして、ドキュメントを build() しようとすると、DTD ファイルに対して filenotfound 例外が発生します。私はこのファイルを持っていないことを知っていますし、気にもしていません。XOM を使用している場合、どうすればこのファイルを削除できますか?
コード スニペットを次に示します。
public BlastXMLParser(String filePath) {
Builder b = new Builder(false);
//not a good idea to have exception-throwing code in constructor
try {
_document = b.build(filePath);
} catch (ParsingException ex) {
Logger.getLogger(BlastXMLParser.class.getName()).log(Level.SEVERE,"err", ex);
} catch (IOException ex) {
//
}
private Elements getBlastReads() {
Element root = _document.getRootElement();
Elements rootChildren = root.getChildElements();
for (int i = 0; i < rootChildren.size(); i++) {
Element child = rootChildren.get(i);
if (child.getLocalName().equals("BlastOutput_iterations")) {
return child.getChildElements();
}
}
return null;
}
}
この行で NullPointerException を取得します。
Element root = _document.getRootElement();
ソース XML ファイルから DTD 行を削除すると、正常に解析できますが、これは最終的な運用システムのオプションではありません。