如何为图书设计XML模式?
我的xsd文档有问题,不确定我缺少了什么,因为它无法验证。试图使图书id成为图书的一个属性,并且作者的首字母和姓氏封装在一个author元素中,这样就可以有多个作者的图书如何为图书设计XML模式?,xml,xsd,Xml,Xsd,我的xsd文档有问题,不确定我缺少了什么,因为它无法验证。试图使图书id成为图书的一个属性,并且作者的首字母和姓氏封装在一个author元素中,这样就可以有多个作者的图书 <ArrayOfBook> <Book id="cb001"> <Author> <Initials>Charles</Initials> <Surname>Berlitz</Surname>
<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)?,(unique | Key | Keyref)*)时出错。从:元素开始发现问题
您必须使用以下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>
您必须使用以下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>