如何为图书设计XML架构?

时间:2017-08-10 03:36:01

标签: xml xsd

我的xsd文档出现问题,因为它没有验证,我不知道我错过了什么。试图使书籍id成为书籍的一个属性,作者的姓名和姓氏被封装在一个作者元素中,这样就可以有多本作者书籍。

<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中缺少什么?当我尝试验证&#34;作者的内容时,给我一个错误。必须匹配(注释?,(simpleType | ComplexType)?,(unique | Key | Keyref)*))。找到问题从:元素开始。&#34;

<?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>

1 个答案:

答案 0 :(得分:0)

您必须使用以下XSD来验证您的XML。

  x%>%filter_all(., any_vars( . == min(.)))%>%
 data.frame(.,var=apply(.,1,function(i) names(.)[i==sapply(x,min)]))