如何从WSDL文件中获取复杂类型?

时间:2010-08-11 13:56:00

标签: java wsdl complextype

我有以下wsdl文件:

 <wsdl:types>
  <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema">
   <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>

使用WSDL4J,我可以获得wsdl:types节点:

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

但我无法弄清楚如何在complex types内获取types

如何以编程方式获取复杂类型?我在哪里可以找到一个如何做的例子?

1 个答案:

答案 0 :(得分:0)

尝试做:

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

此时,您实际上只获得了代表架构的org.w3c.dom.Element实例。