具有元素和属性的 XSD 扩展

发布于 2024-12-04 17:26:58 字数 1854 浏览 1 评论 0原文

我需要创建一个 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。所以理想情况下我应该有这样的东西:

<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' 只是元素,但其基本类型不是。

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

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 solving this failed so far.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離殇 2024-12-11 17:26:58

我在 XML 架构编辑器中尝试了您的架构,但您的代码片段没有出现任何错误(我必须将其放在 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 提供)来解析这些名称空间。

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

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?

提笔落墨 2024-12-11 17:26:58

我找不到实现它的方法,这是我的解决方法。我刚刚创建了一个新的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 标签中,我扩展了这个复杂类型:

<xsd:extension base="workaround" >

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" >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文