I have a wsdl that contains request and response elements:
<xsd:element name="someRequest" type="ns:SomeRequest"/>
<xsd:element name="someResponse" type="ns:SomeResponse"/>
This wsdl imports a few xsd's, which contain, among others, these complexTypes:
<xsd:complexType name="SomeRequest">
...
</xsd:complexType>
<xsd:complexType name="SomeResponse">
...
</xsd:complexType>
I want to validate an xml against this wsdl, but I can't get it to work. I'm basically using the method described on http://actimem.com/java/jaxb-validation/#Marshalling_Validation, by marshalling the object and setting a Schema and EventHandler.
If I set the Schema to the xsd, it won't validate because there's no element in the xsd. This is pretty logical, I get the same with other tools. When I use the wsdl as Schema, I get this error because of inline documentation:
s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'.
Is there any way to get this to validate?
Since I'm working on existing projects (currently using Xmlbeans instead of JAXB) with a set workflow, I have to work with a few constraints:
- These schemas were not made by us and can't be edited, so removing the docs or adding the elements isn't an option.
- I would prefer to load the xsd's from 1 place because of duplication and possible human errors. Xsd's are stored in a separate project, which builds jars we include as dependencies in our projects. The jars that contain the xjc generated classes also contain the schemas.
- The xsd's contain a lot of imports.
- Because of namespacing and classloading collisions, I can't use the ObjectFactory generated by xjc. Multiple xsd's have the same namespace but are actually different, and this has caused issues with the wrong ObjectFactory getting loaded in generic projects that use multiple xsd's.
I've tried transforming the schema to add the element manually, but I can't find a way to do it on an existing Schema object. If I do this through DOM manipulation, I get the new schema as a String object, which won't parse into a Schema because the imported xsd's can't be found.
If I copy the xsd's from the jar to the project, I can transform them and get the validation to succeed, but I don't really like this solution. If there's no other way, I'll revert to that, but I would like to find a solution that requires as little work as possible when reusing this method and is the least prone to errors. Other developers will use this code and 1 validate method without needing extra steps to work would be perfect.
I ran into basically this problem before and didn't find a solution then, either. But before, the complexType wasn't the root element and I could just wrap it into other objects until I found an object that was represented as element in the xsd.