• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error with schema validation

 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris, I'll give it a shot and pray it works. Appreciate the pointer!
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your problem something related to this thread?
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic