This discussion is archived
2 Replies Latest reply: Oct 24, 2012 10:54 AM by jtahlborn RSS

JAXB Validation

EdChouaffe Newbie
Currently Being Moderated
Good morning to you all.

I've bean playing a bit with JAXB and was wondering if any of you can help me with validation.
When validating a XML instance document using JAXB, we usually have the followings lines:
...
JAXBContext jc = JAXBContext.newInstance( AClassName.class );
Unmarshaller u = jc.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI);
...
In my case I have to use a WSDL file as schema. Some XML Elements are defined in the WSDL file and others within external XSD files.
Therefore I rather call
...
SchemaFactory sf = SchemaFactory.newInstance( "http://schemas.xmlsoap.org/wsdl/");
...
This doesn't work though. My question is to know whether it is possible to apply validation with JAXB using a WSDL file as schema. If yes, then how?

Best regards.

Edmond
  • 1. Re: JAXB Validation
    965123 Newbie
    Currently Being Moderated
    ...
    SchemaFactory sf = SchemaFactory.newInstance( "http://schemas.xmlsoap.org/wsdl/");
    ...
    This is incorrect. As long as you use XML Schema (within wsdl or xsd files), you should always use
    SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI);
    I haven't tried validation with wsdl like this. But I guess it should be supported. Someone else might provider better clarity.
  • 2. Re: JAXB Validation
    jtahlborn Expert
    Currently Being Moderated
    I don't think it's supported out of the box. you could pull the schema elements out of the wsdl yourself and turn them into Schema instances. there also might be some support for this in newer jaxb impls, see http://stackoverflow.com/questions/2351298/jaxb-customizations-multiple-schemas-inside-wsdl-and-schemalocation

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points