Get WSDL schema elements with WSDL4J

Just a very short snippet to show how one may access schema elements from a WSDL definition by using WSDL4J.

javax.wsdl.xml.WSDLReader wsdlReader11 = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader();
Definition def = wsdlReader11.readWSDL( wsdlUri );
for( Object o : def.getTypes().getExtensibilityElements()) {
	if( o instanceof javax.wsdl.extensions.schema.Schema ) {
		org.w3c.dom.Element elt = ((javax.wsdl.extensions.schema.Schema) o).getElement();
		// Navigate in the DOM model of the schema
		// You can use Schema#getImport() to work with imports
	}
}

Obviously, one better approach could be to get the schema object from WSDL4J and pass it to a XML schema parser then, instead of navigating in the DOM model.
Anyway, I tried this approach, but it is quite heavy then. I will most probably migrate to EasyWSDL as soon as the next release is online. In a first time, it will replace WSDL4J for WSDL 1.1. And later, it should also replace Apache Woden for WSDL 2.0. I think I will talk in details of that soon.


About this entry