XML-在网站上显示验证错误

时间:2018-11-25 20:00:38

标签: xml xsd restriction

如何使验证错误显示在网站上?

xml:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="bib.xsl"?>
<Library
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="bib.xsd">
<Book>
    <Name>Life without limits </Name>
    <Author>Nick Vujicic </Author>
    <Year>2018 </Year>
    <Amount>7999 </Amount>
</Book>
</Library>

xsd:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Library">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Book" minOccurs="0" maxOccurs="unbounded" >
                    <xs:complexType>
                        <xs:sequence >
                            <xs:element name="Name" type="xs:string"/>
                            <xs:element name="Author" type="xs:string"/>
                            <xs:element name="Year">
                                <xs:simpleType>
                                    <xs:restriction base="xs:integer">
                                      <xs:minInclusive value="1900"/>
                                      <xs:maxInclusive value="2016"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="Amount" type="xs:string" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>  
        </xs:complexType>
    </xs:element>   
</xs:schema>

值超出限制时,是否有任何可能的方法可以在Year列中显示错误?因为现在它只显示值,而不考虑限制是否合适

0 个答案:

没有答案