Java Technology & XML - Validate an existing DOM object .

Hi All,Does any body know if it抯 possible to validate an existing DOM object with a schema. I have to use JAXP 1.2 so the JAXP 1.3 validation API is out of the question.Thanks,Jimmy
[209 byte] By [jimmy.coynea] at [2007-11-26 23:04:02]
# 1

This may help you:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

dbf.setNamespaceAware(true);

//create DOM parser

DocumentBuilder parser = dbf.newDocumentBuilder();

//Build DOM tree by parsing xml document

Document document = parser.parse(getClass().getResourceAsStream("test.xml"));

// create a SchemaFactory capable of understanding XML schemas

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

// load an XML schema

Source schemaFile = new StreamSource(getClass().getResourceAsStream("test.xsd"));

Schema schema = factory.newSchema(schemaFile);

// create a Validator instance and validate document

Validator validator = schema.newValidator();

validator.validate(new DOMSource(document));

winaya at 2007-7-10 13:56:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks for the rely but i'm using jdk 1.4 and JAXP 1.2. The solution will not work on these versions. Any other ideas ?thanks again.
jimmy.coynea at 2007-7-10 13:56:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...