Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

XML validation with schema or DTD

Thread view: 
e1-1z7k-2x9v-nh13@emailias.com - 20 Mar 2006 11:41 GMT
I am parsing an XML document and want to enable validation. The
document is a JCA resource adapter deployment descriptor. In JCA 1.0
the deployment descriptor is specified via a DTD. In JCA 1.5 it is
specified by an XML schema. I have the following code:

public Document getXMLDocument(String fileName, boolean validation) {

   Document result = null;
   try {
       DocumentBuilderFactory parserFactory =
DocumentBuilderFactory.newInstance();
       parserFactory.setValidating(true);

//parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",,
       //                       "http://www.w3.org/2001/XMLSchema");
       }
       DocumentBuilder parser = parserFactory.newDocumentBuilder();
       result = parser.parse(new File(fileName));
   } catch (SAXException se) {
       System.err.println(se.getMessage());
   }
   return result;
}

The DTD-specified document parses successfully but the schema-specified
document throws a SAXParseException with the message "Document is
invalid: no grammar found".

If I remove the commented out code, the schema-specified document
parses successfully but the DTD-specified document throws a
SAXParseException with the message "cvc-elt.1: Cannot find the
declaration of element 'connector'."

Other than scanning the file for <!DOCTYPE and conditionally setting
the schema language, is there any way to parse an XML document with
validation regardless of whether it is schema- or DTD-specified?

Kevin
Dave Mandelin - 21 Mar 2006 02:32 GMT
See

http://xerces.apache.org/xerces2-j/faq-pcfp.html

I think you may need to enable 'schema validation' in order to get the
schema-validated version to work. I believe the setAttribute call is
then unnecessary. The 'dynamic validation' feature may be relevant as
well.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.