• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Problems validating XML document against schema document

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize in advance if my question and code seem frazzled and/or incoherent- I've been wrestling with this problem for a total of about 10 hours for the past week and I'm somewhat frustrated. Also, in the spirit of full disclosure, this problem is part of a homework assignment. My prof is being deliberately unhelpful (feels that way, anyhow), and I think my classmates are having similar issues.
I am trying to validate a very simple XML document against a (seemingly) simple Schema file. I'm doing this as part of creating a custom object. I'll admit that I don't know if this is the best or even a good way to go about doing this, it's just the easiest for me to work with at this stage.

Whenever I run my program, the XML document parses fine, but I get this error in the output window:

Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this.
Error: URI=file:/Z:/EDU/UMUC/Advanced%20Java%20Programming/Project%202/SWSmith_Network/RequestXMLTest.xml Line=2: Document is invalid: no grammar found.
Error: URI=file:/Z:/EDU/UMUC/Advanced%20Java%20Programming/Project%202/SWSmith_Network/RequestXMLTest.xml Line=2: Document root element "FILESEARCH", must match DOCTYPE root "null".

BUILD SUCCESSFUL (total time: 7 seconds)

Rather than be coy about this, I'm going to post EVERYTHING (sorry if it's a lot to take in):

My main method:

XMLParseServer class fields and constructor:

RequestXMLTest.xml file:

requestschema.xsd file:

Again, totally frustrated at this stage- any thoughts or insights offered are greatly appreciated.

Thanks for your time,

S. William Smith
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I kept playing with it and figured it out. I'll post this my solution even though I'm not sure how much use this will be to anyone else- except that I followed a tutorial somewhere that caused me some confusion; maybe this can resolve that.

First, I was making so many changes I lost track of what I had done. In my schema file I was mixing up my namespaces- interchanging XS and XSD in a couple of places.

Second, in my XMLParseServer class when I was setting the schema attributes (factory.setAttribute(JAXP_SCHEMA_LANGUAGE, schemaFileName);) I should not have replaced the W3C_XML_SCHEMA constant with my own schema file String object. According to the tutorial I read you can create an array of Strings containing these file names but you can't place a single String or String object with the file name in that location. Although the method accepts it, it evidently doesn't work that way.

Like I said, this may not be much help to anyone else since these mistakes were my own, but you never know.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic