views:

49

answers:

1

I have the following wsdl file:

 <wsdl:types>
  <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"&gt;
   <import namespace="http:..."/>
   <complexType name="BaseBean">
    <sequence/>
   </complexType>
   <complexType name="DateBean">
    <complexContent>
     <extension base="impl:BaseBean">
      <sequence>
       <element name="date" nillable="true" type="xsd:dateTime"/>
      </sequence>
     </extension>
    </complexContent>
   </complexType>
  </schema>
 </wsdl:types>

Using WSDL4J, I can get the wsdl:types node:

WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
Definition definition = reader.readWSDL("file.wsdl");
Types types = definition.getTypes();

But I cannot figure out how to get the complex types inside the types.

How can I get the complex types programatically? Where can I find an example on how do do it?

A: 

Try doing:

Schema schema = null;
for (Object e : types.getExtensibilityElements()) {
    if (e instanceof Schema) {
        schema = (Schema)e;
        break;
    }
}
if (schema != null) {
    Element schemaElement = schema.getElement();
    // ...
}

At this point, you really only get an org.w3c.dom.Element instance that represents the schema.

kschneid
tried this before. it returns a strange [schema: null] reference.
Paulo Guedes
@Paulo - but did you actually try doing anything with the Element besides printing it? Like, what does `schemaElement.hasChildNodes()` return?
kschneid
`hasChildNodes()` returns `true`. but the `schema.getElement()` itself returns an object whose attributes are `elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"` but no way to grab the complex types. :/
Paulo Guedes
@Paulo - clearly that depends on what you mean by "grab the complex types". another option would be to process the wsdl with a tool like wsimport to generate jaxb classes for your schema types. see the jax-ws ri at: https://jax-ws.dev.java.net/
kschneid
@kschneid, I mean, I would like to have something like `getComplexTypes()` for example. I need to iterate over the complex types inside the schema. External tools are not useful for me, I need to do this programatically.
Paulo Guedes