Using JDOM and JAXP v1.1 to validate XML

I have a JDOM Document object which is constructed by my program. I need to validate the Document object against an XML schema on the fly (i.e. without saving the XML doc to the file system). I thought it might work to print the Document to standard output and have XMLReader parse that:

xmlReader.parse(new InputSource(new InputStreamReader(

System.in)));

but the parse method blocks waiting for input. For some reason it also doesn't work when I run the code in a different thread.

Any hints would be greatly appreciated. Should I use another class other than XMLReader?

Thanks,

C.R.

Message was edited by:

C.R.Cren

[740 byte] By [C.R.Crena] at [2007-11-27 8:52:10]
# 1
For validation with JAXP and JDOM please refer http://javaboutique.internet.com/tutorials/jdomjaxp/
dvohra09a at 2007-7-12 21:07:04 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

For in-memory validation using a JDOM Document object things are a bit trickier. I have found that this works:

xmlOutputter.output(jdomDoc, strWriter);

strReader = new StringReader(strWriter.toString());

saxParser.parse(new InputSource(strReader), new ValidationHandler());

Thanks for your input!

~C.R.

C.R.Crena at 2007-7-12 21:07:04 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...