如何为没有包装元素的列表编写 XSD [英] How to write an XSD for a list with no wrapper element

查看:21
本文介绍了如何为没有包装元素的列表编写 XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让 xsd:complexType 包含 xsd:sequencexsd:element?

Is it possible to have xsd:complexType contains xsd:sequence and xsd:element?

<xsd:complexType name="employeesType" mixed="true">
    <xsd:sequence>
        <xsd:element name="employee" type="employeeType"
            maxOccurs="unbounded" minOccurs="0" />
    </xsd:sequence>
    <!-- ERROR
    <xsd:element name="responseTime" type="responseTimeType"></xsd:element>
     -->
</xsd:complexType>

推荐答案

如您在上面的示例中所示,不允许将 <xsd:element/> 作为直接子级<xsd:complexType/>(参见 w3schools.com 上的参考).考虑到您上一个问题中的示例,我认为您想做什么可以使用这样的模式来实现:

As you show in your example above it is not allowed to have an <xsd:element /> as a direct child of <xsd:complexType /> (see reference at w3schools.com). Considering the example from your previous question I think what you want to do can be achieved with a schema like this:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="date" type="xsd:string" />
            <xsd:element name="responseTime" type="xsd:decimal" />
            <xsd:element name="employee" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="name" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
</xsd:schema>

这验证了您的示例代码:

This validates for your example code:

<?xml version="1.0"?>
<root>
    <date> 9:51 AM 10/10/2012 </date>
    <responseTime> 1.20</responseTime>
    <employee>
        <name> Mohammad</name>
    </employee>
    <employee>
        <name> Ali</name>
    </employee>
    <employee>
        <name> Mostafa</name>
    </employee>
    <employee>
        <name> Mahmoud</name>
    </employee>
</root>

不过,您可能希望将 的类型更改为 xsd:date.

You might want to change the type of <date /> to xsd:date though.

这篇关于如何为没有包装元素的列表编写 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆