Hi everybody,
Have just started playing with XML and Schemas using the out of the box java factory classes that came with 1.5. I'm having some trouble getting it to validate any (i've tried this with tutorials files, samples and my own all get the same errors) XML file againist a schema without throwing these errors
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
org.xml.sax.SAXParseException: Document root element "book", must match DOCTYPE root "null".
cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'book'.
I think what going on is a problem in the parser thinking that the XML file gotta conform to some DTD standards (the DOCTYPE line is'nt needed when using Schemas right?). So does anyone know how to stop these coming up or do you just have to ignore them? The code im using is
Is this the right method? do i need to set some more settings in the parser?
Any thoughts ideas critique welcome as this has got me well fuddled!
Cheers
Coup
Have just started playing with XML and Schemas using the out of the box java factory classes that came with 1.5. I'm having some trouble getting it to validate any (i've tried this with tutorials files, samples and my own all get the same errors) XML file againist a schema without throwing these errors
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
org.xml.sax.SAXParseException: Document root element "book", must match DOCTYPE root "null".
cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'book'.
I think what going on is a problem in the parser thinking that the XML file gotta conform to some DTD standards (the DOCTYPE line is'nt needed when using Schemas right?). So does anyone know how to stop these coming up or do you just have to ignore them? The code im using is
Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
SchemaFactory sFact = SchemaFactory.newInstance(lang);
Schema schema = sFact.newSchema(schemaFile); factory.setSchema(schema);
DocumentBuilder dommer = factory.newDocumentBuilder();
dommer.setErrorHandler(new MetaSaxErrorHandler());
Document doco = dommer.parse(xmlFile.getAbsolutePath());
Any thoughts ideas critique welcome as this has got me well fuddled!
Cheers
Coup