wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Throws IllegalArguementException when validating XML with schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Throws IllegalArguementException when validating XML with schema" Watch "Throws IllegalArguementException when validating XML with schema" New topic
Author

Throws IllegalArguementException when validating XML with schema

Anand Loganathan
Greenhorn

Joined: Sep 13, 2003
Posts: 12
I am working on WebServices project which involves JAX-RPC.
I am receiving XML document from Service Endpoint . I need to validate this XML against schema (XSD). but when I doing, it throws Illegal Arguement exception.

The error is throwing after the execution of the line
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

Following is my code.
=============================

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
System.out.println("DocumentBuilderFactory: "+ factory.getClass().getName());

factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

// Specify our own schema - this overrides the schemaLocation in the xml file

// Error throws after executing this below line.
//factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "file:./test.xsd");

DocumentBuilder builder = factory.newDocumentBuilder();
DefaultHandler er = new DefaultHandler();
builder.setErrorHandler( er );
InputSource in = new InputSource(new StringReader(xml));


Document document = builder.parse(in);
Node rootNode = document.getFirstChild();
System.out.println("Root node: "+ rootNode.getNodeName() );


=================================
I am not sure why it is throwing this error.

Any idea/suggestion is highly appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Throws IllegalArguementException when validating XML with schema
 
Similar Threads
Parse/Validate with DSIG schema issue
Read File from jar file
Validating xml against xsd
xml parsing problem using xerces
Help for warning: src-import.0: Failed to read imported schema document