python - how to avoid inheritance when using JAXB schemagen? -


i'm using jaxb annotations , schemagen maven plugin create xsd. need process xsd wsdl2py create python's client. have inheritance in classes, schemagen creates this:

<xs:complextype name="b">   <xs:complexcontent>     <xs:extension base="a">       <xs:sequence>         <xs:element name="field1" type="xs:string"/>       </xs:sequence>     </xs:extension>   </xs:complexcontent> </xs:complextype> 

for class:

class b extends a{   @xmlelement(required="true")   private string field1; } 

the problem wsdl2py doesn't understand xs:complexcontent , xs:extension. i'd generate xsd without inheritance.

thanks in advance

this shortcoming of wsdl2py rather jaxb, it's easy fix, using xslt or xquery. quick attempt fix in 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 <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> 

a couple of notes: works extension, not restrictions, , uses nested sequence wsdl2py may or not support (should easy fix). currently, supports content model, easyly extend copy attributes , attributegroups.

also, stylesheet works when extended element exists in same schema file base.

good luck!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -