• Post Reply Bookmark Topic Watch Topic
  • New Topic

Throws IllegalArguementException when validating XML with schema  RSS feed

Anand Loganathan
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.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.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!