• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

continuing with the deprecated problem.

 
anand chouti
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initially I used the DocumentHandler which is deprecated now. The code is as below.
//code starts here
public class ValidateSAXParser implements DocumentHandler {
public void saxParser(String sRequestXML) throws InvalidXMLException {
try {
StringBufferInputStream stringBufferInStream = new StringBufferInputStream(sRequestXML);
InputSource inputSource = new InputSource((InputStream) stringBufferInStream);
Parser parser;
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(this.bValidate);
SAXParser sp = spf.newSAXParser();
parser = sp.getParser();
parser.setDocumentHandler(this);
objDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
parser.parse(inputSource);
} catch (SAXParseException err) {
throw new InvalidXMLException(ExceptionConstants.AIRBUS_HPGPARTS_INVALID_XML_EXCEPTION);
} catch (Throwable t) {
throw new InvalidXMLException(ExceptionConstants.AIRBUS_HPGPARTS_INVALID_XML_EXCEPTION);
}
}
}
// code ends here

But now I use the ContentHandler in place of DocumentHandler and XMLReader in place of Parser. But there are problems all around. What do i do for the
following line :
spf.setValidating(this.bValidate);
And also what are the other changes to be made.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change

into

And make the class referred to by "this" extend org.xml.sax.helpers.DefaultHandler, i.e.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic