xml - 验证 xsd 方案

标签 xml xsd

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

这是我的方案

<?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)*)).

最佳答案

您有一个围绕 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>

关于xml - 验证 xsd 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33915260/

相关文章:

java - 如何找回 "Eclipse >Generate>Jaxb classes"选项?

php - SimpleXML 不返回属性

java - 使用vtd-xml解析xml文件

java - xml解析字符串匹配Java

java - 我为本地 sqlite 数据库创建了应​​用程序,但它没有运行。请告诉我解决方案

c# - 无法反序列化 WCF 代理类

xml - 在 xsd 文件(xml 架构)的元素或属性名称中转义冒号 ':'

java - 无法将名称解析为 (n) 'type definition' 组件

xml - Scala:给定一个 scala.xml.Node,获取第二个(或第 n 个)子元素的最有效方法是什么?

Java/XSD 解析