开发者

XSD Extension with Element AND Attribute

I need to create an XSD which would validate the following type of XML:

<dbengine stylesheet="file:transformation.xslt">
   <queries>
      <query name="update" inputtype="file">file:/src/test.sql</query>
      <query name="update" inputtype="sql">select * from test</query>
   </queries>
</dbengine>

This can be done by formulating the following schema:

<xsd:element name="dbengine">
    <xsd:complexType>   
        <xsd:sequence>
            <xsd:element name="queries" type="queries" minOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="stylesheet" type="xsd:string" use="optional"/>
    </xsd:complexType>
</xsd:element>

Additionally, I need this tag to be able to receive and send messages from/to a channel by extending inputOutputEndpointType from http://www.springframework.org/schema/integration/spring-integration-1.0.xsd. So ideally I should have something like this:

<xsd:element name="dbengine">
    <xsd:complexType>
        <xsd:complexContent>            
            <xsd:extension base="int:inputOutputEndpointType" >
                <xsd:sequence>
                    <xsd:element name="queries" type="queries" minOccurs="1"/>
                </xsd:sequence>         
            <xsd:attribute name="stylesheet" type="xsd:string" use="optional"/>         
            </xsd:extension>                        
        </xsd:complexContent>       
    </xsd:complexType>
</xsd:element>

However this results in an error (in the eclipse editor):

cos-ct-extends.1.4.3.2.2.1.a: The content type of a derived type and that of its base must both be mixed or both be element-only. Type '#AnonType_dbengine3' is element only, but its base type is not.

Adding the mixed="true" attribute doesn't help and every other attempt of solv开发者_运维知识库ing this failed so far.


I tried your schema in my XML Schema editor and I did not get any error for your snippet (I had to put it within an xsd:schema, and add a dummy definition for the queries complex type).

I think you're simply experiencing an issue with the Eclipse editor. The living proof is in the same file, please take a look at the "innerEndpointDefinitionAware" complexType.

One thing you should try with Eclipse is to actually download spring-integration-1.0.xsd, spring-beans-2.0.xsd and sprint-tool-2.0.xsd in the same folder. Edit the integration file to make sure that for the xsd:imports you manually add the schemaLocation to the files you've downloaded. Try again and see what happens. If it works, the issue is then related to the "dangling" approach used by almost all of the Spring schemas (use of xsd:import without the schemaLocation). With dangling definitions, it is up to the schema processor (in your case provided by Eclipse) to resolve those namespaces.

With my editor it worked even without downloading, after I've configured it to resolve the dangling definitions to the appropriate versions of the beans and tools - maybe Eclipse supports the same?


I couldn't find a way to implement it, here my workaround. I just created a new complexType which substitutes spring inputOutputEndpointType.

<xsd:complexType name="workaround">
    <xsd:attribute name="output-channel" type="xsd:string">
        <xsd:annotation>
            <xsd:appinfo>
                <tool:annotation kind="ref">
                    <tool:expected-type type="org.springframework.integration.core.MessageChannel" />
                </tool:annotation>
            </xsd:appinfo>
        </xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="input-channel" type="xsd:string">
        <xsd:annotation>
            <xsd:appinfo>
                <tool:annotation kind="ref">
                    <tool:expected-type type="org.springframework.integration.core.MessageChannel" />
                </tool:annotation>
            </xsd:appinfo>
        </xsd:annotation>                   
    </xsd:attribute>
    <xsd:attribute name="order" type="xsd:string">
    </xsd:attribute>
    <xsd:attribute name="auto-startup" type="xsd:string" />
</xsd:complexType>

in the dbengine tag I extend this complexType:

<xsd:extension base="workaround" >
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜