XML Schema File that validates my XML File I just want to know if my schema file is correct:

XML File:

  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:books xmlns="http://www.w3.com/1999/XML/prjXMLValidation"
   xmlns:xs="http://www.w3.org/2001/XMLSchema/prjXMLValidation"
      xs:noNamespaceSchemaLocation="collection.xsd"&gt;
   &lt;xs:book title="A Lesson Before Dying" author="Ernest J. Gaines" version="1"&gt;
&lt;xs:stars&gt;
     5
    &lt;/xs:stars&gt;
    &lt;xs:description&gt;
  This is a story about a young man that was wrongly
  accused of killing a white man in the south at a time
  when blacks were not given the same rights as whites.
  This is the story of how Jefferson becomes a man.
    &lt;/xs:description&gt;
&lt;xs:thoughts&gt;
    Great book!
&lt;/xs:thoughts&gt;
  &lt;/xs:book&gt;
&lt;/xs:books&gt;


Here is my XSD File:

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
       targetNamespace="http://www.w3.org/2001/XMLSchema/prjXMLSchema"&gt;
  &lt;xs:element name="books"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:element name="book"&gt;
        &lt;xs:complexType&gt;
          &lt;xs:sequence minOccurs="1" maxOccurs="unbounded"&gt;
            &lt;xs:element name="stars"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:choice minOccurs="0" maxOccurs="1"&gt;
                  &lt;xs:element ref="1" /&gt;
                  &lt;xs:element ref="2" /&gt;
                  &lt;xs:element ref="3" /&gt;
                  &lt;xs:element ref="4" /&gt;
                  &lt;xs:element ref="5" /&gt;
                &lt;/xs:choice&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
            &lt;xs:element name="description" type="xs:string" /&gt;
            &lt;xs:element name="thoughts" type="xs:string" /&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="title" type="xs:string" use="required" /&gt;
          &lt;xs:attribute name="author" type="xs:string" use="required" /&gt;
          &lt;xs:attribute name="version" type="xs:string" /&gt;
        &lt;/xs:complexType&gt;
      &lt;/xs:element&gt; 
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt; 
&lt;/xs:schema&gt;
Overall your structures look OK. Your actual XML document could be indented more neatly, but it's OK.

I would recommend that you change your stars element to have an attribute. Using the PCDATA space is not a great place to put a numeric value.... Actually, I would recommend adding a stars attribute to the thoughts element (seems like a logical place to put it)....

&lt;xs:thoughts stars="5" &gt;
    Great book!
&lt;/xs:thoughts&gt;


This brings up the validation of the stars value too.... you have broken references in your XSD:

          &lt;xs:complexType&gt;
            &lt;xs:choice minOccurs="0" maxOccurs="1"&gt;
              &lt;xs:element ref="1" /&gt;
              &lt;xs:element ref="2" /&gt;
              &lt;xs:element ref="3" /&gt;
              &lt;xs:element ref="4" /&gt;
              &lt;xs:element ref="5" /&gt;
            &lt;/xs:choice&gt;
          &lt;/xs:complexType&gt;


The references 1 .... 5 are not declared. This is a problem. But, you should be using references (just not those ones....). You should be separating out your XSD types and then merging them up in complex-types with ref references. You should also be declaring the types outside of their usage... which makes things easier to manage.

Consider the following (which changes the stars validation, and location).

&lt;xs:simpleType name="startype"&gt;
  &lt;xs:restriction base="xs:string"&gt;
    &lt;xs:pattern value="[1-5]"/&gt;
  &lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;

.....
&lt;xs:element name="thoughts"&gt;
  &lt;xs:complexType&gt;
    &lt;xs:simpleContent&gt;
      &lt;xs:extension base="xs:string"&gt;
        &lt;xs:attribute name="stars" type="startype" /&gt;
      &lt;/xs:extension&gt;
    &lt;/xs:simpleContent&gt;
  &lt;/xs:complexType&gt;
&lt;/xs:element&gt;