0

Is it possible to validate the large xml part by part?

For eg

<retail>
<pdt>
</pdt>
<pdt>
</pdt>
<pdt>
</pdt>
</retail>

consider it as a large xml file.I need to validate against a xsd and my validator should return true even if any one of the pdt is successfully validated and should also give reason why others failed.

artbristol
  • 32,010
  • 5
  • 70
  • 103
vino
  • 119
  • 1
  • 8

2 Answers2

0

First of all refer to this XML validation in Java. For your requirement "need to validate against a xsd and my validator should return true even if any one of the pdt is successfully validated and should also give reason why others failed"

make a custom ErrorHandler by implementing org.xml.sax.ErrorHandler interface and then register this as the errorhandler in the validator object in the given example like this :

 validator.setErrorHandler(new CustomValidationErrorHandler());

Make sure you do this before calling validate() method. In your CustomErrorHandler you can log the exceptions that you will get while validating to see what all was wrong with your xml and dont throw that exception if you want to continue with the validation. You will get it when you will start implementing this.

Community
  • 1
  • 1
Sikorski
  • 2,653
  • 3
  • 25
  • 46
  • @Sirkorski Thank you very much for your help.It works!!.Actually i already have xml validation code which u refer in "XML Validation in Java link". – vino Aug 09 '12 at 03:51
  • then you may check it as an answer :) – Sikorski Aug 09 '12 at 06:00
0

The JAXP validate() method accepts a Source, so you should be able to supply a DOMSource that wraps the pdt element node. However, this assumes that the schema contains a global element declaration for element pdt.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164