1

I tried to create a XML Schema for a dataset, but I got these errors:

  1. The "Extra content at the end of the document" error appeared when i tried to open the XML file.

  2. The "The markup in the document following the root element must be well-formed" error from the EditiX XML Editor.

  3. The "Multiple possible root nodes found" error from the https://codebeautify.org/xmlvalidator.

The errors 1 and 3 appear at the 129 line and the error 2 at the 128 line, which are under the XML Schema, at the first 2 lines of the dataset.

Here is the code:

<?xml  version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:complexType name="Chessdata">
<xs:element name="NumberofGame" type="xs:integer">
   <xs:simpleContent>
     <xs:restriction base="xs:integer">
         <xs:pattern value="([0-9])+"/>
     </xs:restriction>
    </xs:simpleContent>
    </xs:element>
<xs:element name="GameID" type="xs:string">
         <xs:simpleType>
             <xs:restriction base="xs:string">
                 <xs:pattern value="[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]"/>
             </xs:restriction>
         </xs:simpleType>
     </xs:element>
     <xs:element name="WhiteRating" type="xs:integer">
         <xs:simpleType>
             <xs:restriction base="xs:integer">
                 <xs:pattern value="([0-9])+"/>
                 <xs:minInclusive value="0"/>
             </xs:restriction>
         </xs:simpleType>
     </xs:element>
     <xs:element name="OpeningECO" type="xs:string">
         <xs:simpleType>
             <xs:restriction base="xs:string">
                 <xs:pattern value="[A-Z][0-9][0-9]"/>
             </xs:restriction>
         </xs:simpleType>
     </xs:element>
     <xs:element name="OpeningPly" type="xs:integer">
         <xs:simpleType>
             <xs:restriction base="xs:string">
                 <xs:pattern value="([0-9])+"/>
             </xs:restriction>
             <xs:restriction base="xs:integer">
                 <xs:minInclusive value="0"/>
             </xs:restriction>
         </xs:simpleType>
     </xs:element>
 </xs:complexType>
</xs:schema>


Here is the how the dataset is:

<Records>
  <Record>
    <Row B="GameID" C="WhiteRating" E="OpeningECO" F="OpeningPly" A="NumberofGame" />
  </Record>
  <Record>
    <Row A="0" B="J7Xvjkte" C="1441" E="C20" F="4" />
  </Record>

................................................................................................................

  <Record>
    <Row A="18636" B="JGfeESug" C="1256" E="C00" F="3" />
  </Record>
</Records>

Do you know how can I fix them?

P.S. I am a totally beginner on XSD who learnt the basics in order to make a project for the university and it is my first post on the Stack Overflow so sorry if the issue with the errors is something simple and sorry if I didn't explain something properly.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Are Errors thrown by the xsd? If dataset contains Records, Record, Row elements, the xsd should too. – LMC Aug 10 '22 at 18:58

1 Answers1

0

Fundamentals of XSD validation of an XML document:

  1. Validation checks that the vocabulary (names of XML elements and attributes) and grammar (structure and type of XML elements and attributes) of an XML document conform to the constraints of a schema (XSD). There are many very basic disagreements between your XML and XSD:

    • None of the elements or attributes used in your XML are defined by your XSD.

    • None of the elements defined in your XSD appear in your XML.

    • There are attribute values in your XML that correspond to element names defined in your XSD, but this clearly plays no useful role in validation as it confuses element names with attribute values.

    To correct these problems, eliminate each of these disagreements by changing either the XML or XSD, depending on which is to be taken as fixed. An XSD tutorial or XSD reference book will help more than online Q/A to build foundational understanding.

  2. XML must be well-formed before it can be valid:

    • The errors that you posted indicate that your XML or XSD are not well-formed, but both your XML and your XSD are indeed well-formed.

    • One way those documents might be made to be not well-formed would be to put them into a single file and attempt to validate (or even just parse) them together. Unlike DTD's internal subset, there is no standard way to embed an XSD into a XML document.

    To get past this problem, separate your XSD and XML into their own files, and use the configuration mechanism of your XSD validator to associate the XSD with the XML, or use standard hints to make the connection: How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

  3. XSD files themselves have to follow specific composition rules. Your XSD has numerous structural problems (that will continue to be a problem even after you eliminate the well-formedness errors of #2 by separating the XML and XSD into different files). It would take an extensive XSD tutorial or a XSD reference book to convey an understanding needed to correct all of the problems, but here are a few points to get you started:

    • ✅ Start with xs:schema
    • ❌ Beneath xs:schema, define the XML root element with xs:element.
    • ❌ Adopt an XSD design pattern.

    To follow these tips and get past the structural problems of your XSD, you'll want to shore-up your understanding of key concepts via an XSD tutorial and reference book as mentioned previously.

Online Q/A is better suited to address limit-scope, single issues at a time than overall learning needs. Nonetheless, hopefully the above guidance will help you move beyond your current impasse. Good luck.

kjhughes
  • 106,133
  • 27
  • 181
  • 240