2014-01-04 4 views
0

У меня есть следующий XML:Ошибка проверки из XSD

<?xml version="1.0"?> 
<BookStore xmlns="http://www.books.org" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation= 
         "http://www.books.org 
         BookStore.xsd"> 
<Book category="Life style"> 
    <Status>Available</Status> 
    <Title lang="en">Hour before dawn</Title> 
    <Author> 
     <Name>Paul McCartney</Name> 
     <Genre>M</Genre> 
    </Author> 
    <Date> 
     <Day>23</Day> 
     <Month>03</Month> 
     <Year>1999</Year> 
    </Date> 
    <Price type="euro">29.99</Price> 
    <ISBN>1-56592-245-2</ISBN> 
    <Publisher>McMilli Publishing</Publisher> 
</Book> 
<Book category="Philosophy"> 
    <Status>Not available</Status> 
    <Title lang="de">Thus spoke Zarathustra</Title> 
    <Author> 
     <Name>Friedrich Nietzsche</Name> 
     <Genre>M</Genre> 
    </Author> 
    <Date> 
     <Day>21</Day> 
     <Month>11</Month> 
     <Year>1877</Year> 
    </Date> 
    <Price type="euro">39.15</Price> 
    <ISBN>0-440-34319-4</ISBN> 
    <Publisher>Sell Publishing Co.</Publisher> 
</Book> 
<Book category="Fiction"> 
    <Status>Available</Status> 
    <Title lang="en">To kill a mockingbird</Title> 
    <Author> 
     <Name>Harper Lee</Name> 
     <Genre>M</Genre> 
    </Author> 
    <Date> 
     <Day>15</Day> 
     <Month>03</Month> 
     <Year>1982</Year> 
    </Date> 
    <Price type="euro">35.15</Price> 
    <ISBN>0-454-25215-8</ISBN> 
    <Publisher>Harper Row</Publisher> 
</Book> 
<Book category="Fantasy"> 
    <Status>Available</Status> 
    <Title lang="en">Hexed</Title> 
    <Author> 
     <Name>Ilona Andrews</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Author> 
     <Name>Yasmine Galenorn</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Author> 
     <Name>Allyson James</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Author> 
     <Name>Jeanne Stein</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Date> 
     <Day>01</Day> 
     <Month>01</Month> 
     <Year>2011</Year> 
    </Date> 
    <Price type="euro">19.8</Price> 
    <ISBN>3-521-77423-9</ISBN> 
    <Publisher>Harper &amp; Row</Publisher> 
</Book> 
<Book category="Web"> 
    <Status>Not available</Status> 
    <Title lang="en">SCJP Sun certified programmer for Java 6</Title> 
    <Author> 
     <Name>Kathy Sierra</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Author> 
     <Name>Bert Bates</Name> 
     <Genre>M</Genre> 
    </Author> 
    <Date> 
     <Day>06</Day> 
     <Month>09</Month> 
     <Year>2011</Year> 
    </Date> 
    <Price type="euro">55</Price> 
    <ISBN>2-421-52214-1</ISBN> 
    <Publisher>Learnkey</Publisher> 
</Book> 
<Book category="Horror"> 
    <Status>Available</Status> 
    <Title lang="en">Out of the depths</Title> 
    <Author> 
     <Name>Cathy MacPhail</Name> 
     <Genre>F</Genre> 
    </Author> 
    <Date> 
     <Day>08</Day> 
     <Month>12</Month> 
     <Year>2013</Year> 
    </Date> 
    <Price type="euro">41</Price> 
    <ISBN>7-666-21242-7</ISBN> 
    <Publisher>Greenock</Publisher> 
</Book> 
<Book category="Art and design"> 
    <Status>Available</Status> 
    <Title lang="en">The design of everyday things</Title> 
    <Author> 
     <Name>Donald Norman</Name> 
     <Genre>M</Genre> 
    </Author> 
    <Date> 
     <Day>27</Day> 
     <Month>02</Month> 
     <Year>2002</Year> 
    </Date> 
    <Price type="euro">26</Price> 
    <ISBN>8-4322-62332-6</ISBN> 
    <Publisher>Basic books</Publisher> 
</Book> 

Я проверенный онлайн в XML, и хорошо сформирован. Затем я сделал схему:

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://www.books.org" 
     xmlns="http://www.books.org" 
     elementFormDefault="qualified"> 
<xsd:element name="BookStore"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="Book" maxOccurs="unbounded"> 
      <xsd:complexType> 
       <xsd:sequence> 
        <xsd:element name="Status"> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
           <xsd:pattern value="Available|Not available"> 
           </xsd:pattern> 
          </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        <xsd:element name="Title"> 
         <xsd:complexType> 
          <xsd:attribute name="en" type="xsd:string" use="required"/> 
         </xsd:complexType> 
        </xsd:element> 
        <xsd:element name="Author" minOccurs="1" maxOccurs="unbounded"> 
         <xsd:complexType> 
          <xsd:sequence> 
           <xsd:element name="Name"> 
            <xsd:simpleType> 
             <xsd:restriction base="xsd:string"> 
              <xsd:pattern value="[a-zA-Z]+\\s[a-zA-Z]+"> 
              </xsd:pattern> 
             </xsd:restriction> 
            </xsd:simpleType> 
           </xsd:element> 
           <xsd:element name="Genre"> 
            <xsd:simpleType> 
             <xsd:restriction base="xsd:string"> 
              <xsd:enumeration value="M"/> 
              <xsd:enumeration value="F"/> 
             </xsd:restriction> 
            </xsd:simpleType> 
           </xsd:element> 
          </xsd:sequence> 
         </xsd:complexType> 
        </xsd:element> 
        <xsd:element name="Date"> 
         <xsd:complexType> 
          <xsd:sequence> 
           <xsd:element name="Day"> 
            <xsd:simpleType> 
             <xsd:restriction base="xsd:positiveInteger"> 
              <xsd:minInclusive value="1"/> 
              <xsd:maxInclusive value="31"/> 
             </xsd:restriction> 
            </xsd:simpleType> 
           </xsd:element> 
           <xsd:element name="Month"> 
            <xsd:simpleType> 
             <xsd:restriction base="xsd:positiveInteger"> 
              <xsd:minInclusive value="1"/> 
              <xsd:maxInclusive value="12"/> 
             </xsd:restriction> 
            </xsd:simpleType> 
           </xsd:element> 
           <xsd:element name="Year"> 
            <xsd:simpleType> 
             <xsd:restriction base="xsd:positiveInteger"> 
             </xsd:restriction> 
            </xsd:simpleType> 
           </xsd:element> 
          </xsd:sequence> 
         </xsd:complexType> 
        </xsd:element> 
        <xsd:element name="Price" type="xsd:decimal">      
        </xsd:element> 
        <xsd:element name="ISBN"> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
           <xsd:pattern value="\d{1}-\d{5}-\d{3}-\d{1}|\d{1}-\d{3}-\d{5}-\d{1}|\d{1}-\d{2}-\d{6}-\d{1}"> 
           </xsd:pattern> 
          </xsd:restriction> 
         </xsd:simpleType>     
        </xsd:element> 
        <xsd:element name="Publisher" type="xsd:string"> 
        </xsd:element> 
       </xsd:sequence> 
       <xsd:attribute name="category" type="xsd:string" use="required"/> 
      </xsd:complexType> 
     </xsd:element> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

Когда я пытаюсь проверить онлайн это, я получаю следующие ошибки: http://www.utilities-online.info/xsdvalidation/?save=72595340-b1e9-4061-a655-c6cfb9cdac44-xsdvalidation#.UsivXPQW1PI Нажмите на кнопку Validate XML против XSD и увидеть все ошибки. Кто-нибудь знает, чтобы решить эту проблему без каких-либо ошибок?

+0

Я не думаю, что вы можете иметь '' * непосредственно * внутри другого ''. Он хочет использовать '' или '' или одну из других вещей, которые он упоминает в «должен совпадать». –

+0

Действительно. Я изменил некоторые ошибки, и у меня есть только одно: Недействительно. Ошибка - строка 7, 51: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 51; s4s-elt-invalid-content.1: Содержимое «#AnonType_BookStore» недействительно. Элемент «элемент» недействителен, неуместен или встречается слишком часто. –

+0

Здесь это новая ссылка с новыми изменениями: https://www.4shared.com/get/LPiGCFc3ce/BookstoreFinal.html. Осталась только одна ошибка. Ошибка, о которой я только что упомянул. Есть идеи? –

ответ

1

Теперь, когда изменения в вопросе, похоже, остались в покое, обновите XSD, чтобы устранить ошибки проверки, которые вы получали при проверке данного экземпляра XML-документа.

Fixed XSD:

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      targetNamespace="http://www.books.org" 
      xmlns="http://www.books.org" 
      elementFormDefault="qualified"> 
    <xsd:element name="BookStore"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="Book" maxOccurs="unbounded"> 
      <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="Status"> 
       <xsd:simpleType> 
        <xsd:restriction base="xsd:string"> 
        <xsd:pattern value="Available|Not available"> 
        </xsd:pattern> 
        </xsd:restriction> 
       </xsd:simpleType> 
       </xsd:element> 
       <xsd:element name="Title"> 
       <xsd:complexType> 
        <xsd:simpleContent> 
        <xsd:extension base="xsd:string"> 
         <xsd:attribute name="lang" type="xsd:string"/> 
        </xsd:extension> 
        </xsd:simpleContent> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="Author" minOccurs="1" maxOccurs="unbounded"> 
       <xsd:complexType> 
        <xsd:sequence> 
        <xsd:element name="Name"> 
         <xsd:simpleType> 
         <xsd:restriction base="xsd:string"> 
          <xsd:pattern value="[a-zA-Z]+\s[a-zA-Z]+"> 
          </xsd:pattern> 
         </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        <xsd:element name="Genre"> 
         <xsd:simpleType> 
         <xsd:restriction base="xsd:string"> 
          <xsd:enumeration value="M"/> 
          <xsd:enumeration value="F"/> 
         </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        </xsd:sequence> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="Date"> 
       <xsd:complexType> 
        <xsd:sequence> 
        <xsd:element name="Day"> 
         <xsd:simpleType> 
         <xsd:restriction base="xsd:positiveInteger"> 
          <xsd:minInclusive value="1"/> 
          <xsd:maxInclusive value="31"/> 
         </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        <xsd:element name="Month"> 
         <xsd:simpleType> 
         <xsd:restriction base="xsd:positiveInteger"> 
          <xsd:minInclusive value="1"/> 
          <xsd:maxInclusive value="12"/> 
         </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        <xsd:element name="Year"> 
         <xsd:simpleType> 
         <xsd:restriction base="xsd:positiveInteger"> 
         </xsd:restriction> 
         </xsd:simpleType> 
        </xsd:element> 
        </xsd:sequence> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="Price">      
       <xsd:complexType> 
        <xsd:simpleContent> 
        <xsd:extension base="xsd:decimal"> 
         <xsd:attribute name="type" type="xsd:string"/> 
        </xsd:extension> 
        </xsd:simpleContent> 
       </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="ISBN"> 
       <xsd:simpleType> 
        <xsd:restriction base="xsd:string"> 
        <xsd:pattern value="\d{1}-\d{5}-\d{3}-\d{1}|\d{1}-\d{3}-\d{5}-\d{1}|\d{1}-\d{2}-\d{6}-\d{1}|\d{1}-\d{4}-\d{5}-\d{1}"> 
        </xsd:pattern> 
        </xsd:restriction> 
       </xsd:simpleType>     
       </xsd:element> 
       <xsd:element name="Publisher" type="xsd:string"> 
       </xsd:element> 
      </xsd:sequence> 
      <xsd:attribute name="category" type="xsd:string" use="required"/> 
      </xsd:complexType> 
     </xsd:element> 
     </xsd:sequence> 
    </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

Minor примечание: Я добавил еще одну форму рисунка ISBN для поддержки ISBN для последней книги: 8-4322-62332-6. Если это неверный формат ISBN, вы должны исключить последний | -clause в шаблоне, который я добавил (\d{1}-\d{4}-\d{5}-\d{1}), и вместо этого исправить ISBN в экземпляре XML-документа.

+0

Это именно то, что мне нужно. Большое спасибо! –

Смежные вопросы