这是 JAXB 而不是 JAXB 的一个缺点wsdl2py
,但使用 XSLT 或 XQuery 很容易解决。快速尝试在 XSLT 中解决此问题:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:template match="xsd:complexType[xsd:complexContent/xsd:extension]">
<xsd:complexType>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="xsd:annotation" />
<xsd:sequence>
<xsl:variable name="typeQName" select="string(xsd:complexContent/xsd:extension/@base)" />
<xsl:variable name="typeName"><xsl:choose>
<xsl:when test="contains($typeQName, ':')">
<xsl:value-of select="substring-after($typeQName, ':')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$typeQName" />
</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:comment>Included from <xsl:value-of select="$typeQName" />):
</xsl:comment>
<xsl:apply-templates select="//xsd:complexType[@name=$typeName]/*" />
<xsl:comment>Original extension:</xsl:comment>
<xsl:apply-templates select="xsd:complexContent/xsd:extension/*" />
</xsd:sequence>
<xsl:apply-templates
select="xsd:attribute | xsd:attributeGroup | xsd:attributeGroup" />
</xsd:complexType>
</xsl:template>
<!-- General copy rule -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
几点注意事项:这仅适用于扩展,不适用于限制,并使用wsdl2py
可能支持或不支持的嵌套序列(应该很容易修复)。目前,它只支持内容模型,但可以很容易地扩展为复制属性和attributeGroups。
此外,样式表仅在扩展元素存在于与基础相同的模式文件中时才有效。
祝你好运!