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
posted
0
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
posted
0
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
posted
0
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?
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.