验证xsd模式

3

我尝试验证我的方案,但总是报告相同的问题。

这是我的方案:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Coches">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Coche" minOccurs="0" maxOccurs="unbounded">
                <xsd:attribute name="anio_fabricacion" type="xsd:string">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Bastidor" type="xsd:string"/>
                            <xsd:element name="Marca" type="xsd:string"/>
                            <xsd:element name="Modelo" type="xsd:string"/>
                            <xsd:element name="Submodelo" type="xsd:string"/>
                            <xsd:element name="Color" type="xsd:string"/>
                            <xsd:element name="Precio" type="xsd:string"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:attribute>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

这是我的XML文档

<Coches>
    <Coche anio_fabricacion="2015">
        <Bastidor>1234567890qwertyQ</Bastidor>
        <Marca>Renault</Marca>
        <Modelo>Megane</Modelo>
        <Submodelo>Coupé</Submodelo>
        <Color>Rojo</Color>
        <Precio>18000</Precio>
    </Coche>
</Coches>

以下是报告的错误信息。

Line:   7
Kind:   Schema Validation Error
Details:    Element '{http://www.w3.org/2001/XMLSchema}element': The content is not valid. Expected is (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*)).
1个回答

2

您有一个将complexType包围的属性是反向的。以下是已更正的架构:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Coches">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Coche" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="Bastidor" type="xsd:string"/>
                        <xsd:element name="Marca" type="xsd:string"/>
                        <xsd:element name="Modelo" type="xsd:string"/>
                        <xsd:element name="Submodelo" type="xsd:string"/>
                        <xsd:element name="Color" type="xsd:string"/>
                        <xsd:element name="Precio" type="xsd:string"/>
                    </xsd:sequence>
                    <xsd:attribute name="anio_fabricacion" type="xsd:string">
                    </xsd:attribute>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

如果这个问题有用的话,你可以在分数下方(当它可用时)打勾来让其他用户知道。 - user764357

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接