Error in XSD document: "s4s-elt-invalid-content.1: The content of 'tab' is invalid."

2

I do not know why the validator on this page ( link ) tells me that I have the wrong XSD document.

The error that gives me concretely is:

  

Not valid. Error - Line 5, 58: org.xml.sax.SAXParseException;
  lineNumber: 5; columnNumber: 58; s4s-elt-invalid-content.1: The   content of 'record' is invalid. Element 'element' is invalid,   misplaced, or occurs too often.

The XSD document is:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="ficha">
        <xs:attribute name="numero" type="xs:decimal"/>
        <xs:element name="nombre" type="xs:NMTOKEN"/>
        <xs:element name="edad" type="xs:decimal"/>
    </xs:complexType>
</xs:schema>

The XML document is:

<?xml version="1.0" encoding="UTF-8"?>
<fichas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemalLocation="fichas.xsd">
  <ficha numero="1">
    <nombre>Ana Sanz Tin</nombre>
    <edad>22</edad>
  </ficha>
  <ficha numero="2">
    <nombre>Iker Rubio Mol</nombre>
    <edad>23</edad>
  </ficha>
</fichas>
    
asked by Carlos 14.02.2018 в 22:23
source

1 answer

1

The .xml document is valid, but the .xsd is invalid.

The error:

  

s4s-elt-invalid-content.1: The content of 'record' is invalid.

Refer to these by reading the "tab" item, but you must first read the "tabs" item to access the "tab":

<?xml version="1.0" encoding="UTF-8"?>
  <fichas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemalLocation="fichas.xsd">
    <ficha numero="1">
    ...
    ...

There are several details that you have in this file; since you have a sequence of <ficha> elements, you must use <xs:sequence> , use type="xs:string" instead of type="xs:NMTOKEN" for nombre .

This .xsd should work correctly:

  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="fichas">
        <xs:complexType mixed="true">
          <xs:sequence>
            <xs:element name="ficha" maxOccurs="unbounded" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element type="xs:string" name="nombre"/>
                  <xs:element type="xs:decimal" name="edad"/>
                </xs:sequence>
                <xs:attribute type="xs:decimal" name="numero" use="optional"/>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    
answered by 14.02.2018 в 22:53