2 Replies Latest reply: Oct 24, 2012 12:54 PM by jtahlborn RSS

    JAXB Validation

    EdChouaffe
      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
          ...
          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
            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