[英]How to design XML schema for book?
我的xsd文档有问题,不确定我所缺少的内容,因为它没有通过验证。 尝试使书籍ID是书籍的属性,并且将作者的姓名缩写和姓氏封装在author元素中,以便可以使用多个作者书籍。
<ArrayOfBook>
<Book id="cb001">
<Author>
<Initials>Charles</Initials>
<Surname>Berlitz</Surname>
</Author>
<Title>The Bermuda Triangle</Title>
</Book>
<Book id="da001">
<Author>
<Initials>Douglas</Initials>
<Surname>Adams</Surname>
</Author>
<Title>The Hitchhiker's Guide to the Galaxy</Title>
</Book>
<Book id="bor001">
<Author>
<Initials>Bill</Initials>
<Surname>O'Reilly</Surname>
</Author>
<Author>
<Initials>Dwight Jon</Initials>
<Surname>Zimmerman</Surname>
</Author>
<Title>Lincoln's Last Days</Title>
</Book>
</ArrayOfBook>
我下面的XSD中缺少什么? 当我尝试验证“作者的内容必须匹配(注释?,(simpleType | ComplexType)?,(唯一| Key | Keyref)*))。给我一个错误。发现一个问题始于:Element。”
<?xml version = "1.0" ?>
<xs:schema id = "ArrayOfBook" xmlns:xs ="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name = "AuthorId">
<xs:restriction base = "xs:string">
<xs:pattern value ="[A-Za-z\s']+"/>
</xs:restriction>
</xs:simpleType>
<xs:element name = "ArrayOfBook">
<xs:complexType>
<xs:sequence>
<xs:element name = "Book" minOccurs = "0" maxOccurs = "unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name = "Author">
<xs:element name="AuthorInitials" type="AuthorId" minOccurs ="1" maxOccurs = "unbounded"/>
<xs:element name="AuthorSurname" type="AuthorId" minOccurs ="1" maxOccurs = "unbounded"/>
</xs:element>
<xs:attribute name="Id" type = "xs:string"/>
<xs:element name="Title" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
您必须使用以下XSD来验证XML。
<?xml version = "1.0" ?>
<xs:schema id="ArrayOfBook" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="AuthorId">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z\s']+"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="ArrayOfBook">
<xs:complexType>
<xs:sequence>
<xs:element name="Book" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Author" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Initials" type="AuthorId" minOccurs="1"
maxOccurs="unbounded"/>
<xs:element name="Surname" type="AuthorId" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Title" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.