1

We are serializing and deserializing Data with java XMLEncoder and XMLDecoder. You can read an object like in the example provided in the javadoc of XMLDecoder:

XMLDecoder d = 
    new XMLDecoder(new BufferedInputStream(new FileInputStream("Test.xml")));
Object result = d.readObject();
d.close();

readObject parses the input and returns an Object, if there is one. If not it will simply throw an ArrayIndexOutOfBoundsException.

I was wondering if there is a way to validate the contents provided to XMLDecoder (in the example above the file content of "Test.xml") in advance so the XMLDecoder can properly work with it. (I am aware set there is a setExceptionHandler Method, however this handler is only called during parsing, which is done when calling readObject). Or is there a "XMLEncoder" dtd or xsd of some sort?

chiwangc
  • 3,566
  • 16
  • 26
  • 32
Benni
  • 357
  • 6
  • 18

0 Answers0