【问题标题】:XSD - <xs:sequence> without <xs:complexType>?XSD - <xs:sequence> 没有 <xs:complexType>?
【发布时间】:2015-10-14 09:32:30
【问题描述】:

我有一个简单的 XML 数据,并希望使用 我的 XSD 文件。我想以任何类型创建 XSD 文件 “面向对象”的方式。因为至少在我看来,理解/阅读会更好。

我的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<DSExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="TestXSD.xsd">

    <Job Identifier="someString1">
        <Project name="someString2">
            <tag1 />
            <tag2 />
        </Project>
    </Job>

</DSExport>

我的 XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <!-- "MAIN" -->
    <xs:element name="DSExport">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Job" type="JobType">

                    <!-- NOTE: SOMETHING WENT WRONG HERE -->
                    <xs:sequence>
                        <xs:element name="Project" type="ProjectType">
                            <xs:sequence>
                                <xs:element name="tag3"></xs:element>
                                <xs:element name="tag4"></xs:element>
                            </xs:sequence>
                        </xs:element>
                    </xs:sequence>
                    <!-- NOTE: SOMETHING WENT WRONG HERE -->

                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!--  "FUNCTIONS" (WANT TO SEPERATE THE SPECIALIZED VALIDATION OF ALL ELEMENTS)-->
    <xs:complexType name="JobType">
        <xs:attribute name="Identifier" type="xs:string" use="required" />
    </xs:complexType>

    <xs:complexType name="ProjectType">
        <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>

我使用日食。我收到任何错误消息,例如:

s4s-elt-must-match.1: The content of 'Job' must match (annotation?, (simpleType | complexType)?, (unique | 
 key | keyref)*)). A problem was found starting at: sequence.

如果我将每个部分都写在“主要”部分中,我知道如何解决它...... 但我怎样才能像“面向对象”一样解决它?我想分开 每个元素的 complexType 定义!

感谢您的帮助!

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    您已经定义了两次 Job 和 Project 元素。您应该像这样将序列移动到类型定义中:

    <xs:element name="DSExport">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Job" type="JobType"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    
    <xs:complexType name="JobType">
        <xs:sequence>
            <xs:element name="Project" type="ProjectType"/>
        </xs:sequence>
        <xs:attribute name="Identifier" type="xs:string" use="required" />
    </xs:complexType>
    
    <xs:complexType name="ProjectType">
        <xs:sequence>
            <xs:element name="tag3"></xs:element>
            <xs:element name="tag4"></xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>
    

    另见:XSD element with both attributes and child elements

    【讨论】:

    • 谢谢老兄!这工作得很好,在我看来这真的是可读的!效果很好!
    猜你喜欢
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多