繁体   English   中英

XSD:无法编译自定义类型

[英]XSD : fail to compile custom type

我尝试为此XML文件创建xsd schame:

<?xml version="1.0"?>
<Listelocataires xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="locataires.xsd">
    <NoImmeuble>221B</NoImmeuble>
        <etage n="1">
            <appartement cote="gauche">
                <nom>Watson</nom>
            </appartement>
            <appartement cote="droit">
                <nom>Holmes</nom>
                <telephone>020 7465 4321></telephone>
            </appartement>
        </etage>
        <etage n="0">
            <appartement cote="droit">
                <nom>Hudson</nom>
                <telephone>020 7465 4321></telephone>
            </appartement>
        </etage>
</Listelocataires>

我尝试创建一个用于验证电话号码的自定义类型,但是它不接受我的回答,这是我的xsd模式:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="Listelocataires">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="NoImmeuble" minOccurs="1" maxOccurs="unbounded" />
                <xsd:element ref="etage" minOccurs="1" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="NoImmeuble" type="xsd:string" />

    <xsd:element name="etage">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="appartement" minOccurs="1" maxOccurs="unbounded" />
            </xsd:sequence>
            <xsd:attribute name="n" type="xsd:string" use="required" /> 
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="appartement">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="nom" minOccurs="1" maxOccurs="unbounded" />
                <xsd:element ref="telephone" minOccurs="0" maxOccurs="unbounded" />
            </xsd:sequence>
            <xsd:attribute name="cote" type="xsd:string" /> 
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="nom" type="xsd:string" />
    <xsd:element name="telephone" type="typeTelephone"/>

    <xsd:simpleType name="typeTelephone">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="\d{3} \d{4} \d{4}" />
        </xsd:restriction>
    </xsd:simpleType>

Xmllint给我这些错误:

locataires.xml:10:元素电话:模式有效性错误:元素“电话”:[facet'pattern']模式'à\\ d {3} \\ d {4}不接受值'à0207465 4321>' \\ d {4}”。 locataires.xml:10:元素电话:模式有效性错误:元素'telephone':'à0207465 4321>'不是原子类型'typeTelephone'的有效值。 locataires.xml:16:元素电话:模式有效性错误:元素“电话”:[facet'pattern']模式'à\\ d {3} \\ d {4}不接受值'à0207465 4321>' \\ d {4}”。 locataires.xml:16:元素电话:模式有效性错误:元素'telephone':'à0207465 4321>'不是原子类型'typeTelephone'的有效值。

我不明白为什么,如果您看到,请帮助我,最好的问候,Zed13

telephone的正则表达式不允许数据中包含尾随>字符。

要成功验证您的XML,请从

<telephone>020 7465 4321></telephone>

<telephone>020 7465 4321</telephone>

而这个来自

<telephone>020 7465 4321></telephone>

<telephone>020 7465 4321</telephone>

或者,从更改XSD正则表达式

        <xsd:pattern value="\d{3} \d{4} \d{4}" />

        <xsd:pattern value="\d{3} \d{4} \d{4}>" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM