File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Error with schema validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Error with schema validation" Watch "Error with schema validation" New topic
Author

Error with schema validation

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
We used to be using JDOM, and if I use the xerces.jar that was with JDOM, then I can validate fine.
However, we switched to Xerces 2.4.0 as our standard, and where I used to validate fine, I now get
SAXParseException: Document root element "das", must match DOCTYPE root "null".
Is this something that I need to change with the schema, or with the XML file (like adding a doctype header)?
Thanks!
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by jason adam:
Is this something that I need to change with the schema, or with the XML file (like adding a doctype header)?

Yes, you need to add a doctype to your XML files. Xerces sometimes gets picky with these things, though it would be nice if Xerces was a bit clearer in its error reporting.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Thanks Chris, I'll give it a shot and pray it works. Appreciate the pointer!
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I'm a bit confused with the examples I've seen. Mind you, I haven't actually been able to play with the DOCTYPE header until today, but examples online always are pointing to, or defining, a DTD. Why would I need to point to a DTD in the DOCTYPE header when I'm also pointing to a schema as an attribute of the root?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Is your problem something related to this thread?


Spritle Software Blogs
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Sounds like the same problem, but haven't discovered how I can avoid having to define a DTD when I already define a schema. We're trying to use schemas as a standard at work, this is putting a kink in that plan.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Found the solution to this little problem, has to do with Features.
To validate, we create a SAXParser and set the validation feature to true. However, the default for this is to use a DTD. To validate against a schema instead of a DTD, you need to set another feature. So the following code validates an XML document against a schema:
SAXParser parser = new SAXParser();
parser.setFeature( "http://xml.org/sax/features/validation" , true );
parser.setFeature( "http://apache.org/xml/features/validation/schema" , true );
This FAQ explains what behaviors will occur when setting the validation and schema features.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error with schema validation
 
Similar Threads
Validating against a schema using the DocumentBuilderFactory
Reading node values in specified datatype in schema( .XSD)
XML validation with Schema checks for the sequence of the elements
Schema Location H*ll
JDOM + Schema