/**
* By subclassing BlackListParseFilter, we can throw an error
* when the parsed XML contains any content we don't want
*/
ParseFilter exceptionFilter = new BlackListParseFilter() {
@Override
public boolean acceptable(QName qname) {
boolean answer = super.acceptable(qname);
if (!(answer)) {
throw new FOMException("Unacceptable element ::" + qname);
}
return answer;
}
@Override
public boolean acceptableAttribute(QName qname, QName attribute) {
return true;
}
};
exceptionFilter.add(new QName("http://example.org", "a"));
ParserOptions options = Parser.INSTANCE.getDefaultParserOptions();
options.setParseFilter(exceptionFilter);
Document<Feed> doc = Parser.INSTANCE.parse(
UnacceptableElementsExample.class.getResourceAsStream("/xmlcontent.xml"),