2017-02-19 48 views
1

я получаю следующее сообщение об ошибке на моем XSD документа:XSD: Ошибка: элемент «атрибут» является недействительным, неуместны, или происходит слишком часто

Element 'attribute' is invalid, misplaced, or occurs too often.

, и я понятия не имею, почему.

Вот мой XSD-файл:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="bookcollection"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="book" maxOccurs="unbounded"> 
      <xs:complexType mixed="true"> 
      <xs:sequence> 
       <xs:element name="name" type="xs:string"/> 
       <xs:element name="image" type="xs:anyURI"/> 
       <xs:element name="quantity" type="xs:string"/> 
       <xs:element name="price"> 
       <xs:complexType> 
        <xs:simpleContent> 
        <xs:extension base="xs:decimal"/> 
        <xs:attribute name="currency" default="EUR" 
            maxOccurs="unbounded"/> 
        <xs:simpleType> 
         <xs:restriction base="xs:string"> 
         <xs:enumeration value="EUR"/> 
         <xs:enumeration value="DOLLARS"/> 
         <xs:enumeration value="ISK"/> 
         </xs:restriction> 
        </xs:simpleType> 
        </xs:simpleContent> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="shipping" type="xs:string"/> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

ответ

2

Чтобы исправить эту ошибку, переместите xs:attribute элемент в xs:extension, а не после него, как представляется, в настоящее время.

Следующая ошибка, которая возникнет, может быть исправлена ​​путем перемещения xs:simpleType в пределах xs:attribute, а не после него, как в настоящее время отображается.

В целом, следующий XSD имеет обе поправки применяется и не имеет никаких дальнейших ошибок:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="bookcollection"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="book" maxOccurs="unbounded"> 
      <xs:complexType mixed="true"> 
      <xs:sequence> 
       <xs:element name="name" type="xs:string"/> 
       <xs:element name="image" type="xs:anyURI"/> 
       <xs:element name="quantity" type="xs:string"/> 
       <xs:element name="price"> 
       <xs:complexType> 
        <xs:simpleContent> 
        <xs:extension base="xs:decimal"> 
         <xs:attribute name="currency" default="EUR"> 
         <xs:simpleType> 
          <xs:restriction base="xs:string"> 
          <xs:enumeration value="EUR"/> 
          <xs:enumeration value="DOLLARS"/> 
          <xs:enumeration value="ISK"/> 
          </xs:restriction> 
         </xs:simpleType> 
         </xs:attribute> 
        </xs:extension> 
        </xs:simpleContent> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="shipping" type="xs:string"/> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

одно замечания, если вы действительно не хотите, чтобы текст между детьми элементами book, удалить mixed="true" из его xs:complexType декларации ,

+0

Спасибо @kjhughes! – JavaApprentice

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

  • Нет связанных вопросов^_^