Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML parsing validation errors

Status
Not open for further replies.

coupster

Programmer
Aug 18, 2005
2
GB
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
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());
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top