带元素和属性的XSD扩展

时间:2011-09-15 10:36:24

标签: xsd complextype

我需要创建一个XSD来验证以下类型的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>

这可以通过制定以下架构来完成:

<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>

此外,我需要此标记能够通过从http://www.springframework.org/schema/integration/spring-integration-1.0.xsd扩展inputOutputEndpointType来从/向通道接收和发送消息。理想情况下,我应该有这样的事情:

<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>

然而,这会导致错误(在eclipse编辑器中):

  

cos-ct-extends.1.4.3.2.2.1.a:派生类型的内容类型和   它的基础必须混合或两者都是元素。类型   '#AnonType_dbengine3'仅为元素,但其基本类型不是。

添加mixed =“true”属性没有帮助,到目前为止,解决此问题的所有其他尝试都失败了。

2 个答案:

答案 0 :(得分:0)

我在我的XML Schema编辑器中尝试了你的模式,我没有得到你的代码片段的任何错误(我必须把它放在xsd:schema中,并为查询复杂类型添加一个虚拟定义)。

我认为您只是遇到了Eclipse编辑器的问题。生活证明在同一个文件中,请查看“innerEndpointDefinitionAware”complexType。

您应该尝试使用Eclipse的一件事是在同一文件夹中实际下载spring-integration-1.0.xsd,spring-beans-2.0.xsd和sprint-tool-2.0.xsd。编辑集成文件以确保为xsd:imports手动将schemaLocation添加到已下载的文件中。再试一次,看看会发生什么。如果它工作,那么问题就与几乎所有Spring模式使用的“悬空”方法有关(使用xsd:import而不使用schemaLocation)。对于悬空定义,由模式处理器(在Eclipse提供的情况下)来解析这些名称空间。

使用我的编辑器,在我将其配置为将豆瓣和工具的适当版本的悬空定义解析后,即使没有下载也可以工作 - 也许Eclipse支持相同的?

答案 1 :(得分:0)

我找不到实现它的方法,这是我的解决方法。我刚刚创建了一个新的complexType,它替换了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>
在dbengine标记中的

我扩展了这个complexType:

<xsd:extension base="workaround" >