I am trying to create a schema for an XML file but keep getting validation errors. I have had plenty of experience with XML, XSLT, and DTD but when I was asked to create a XSD file I thought I could tackle the task. I have been asked to create the schema with the following specifications:
<payroll>
<employee>+
<name>
<first>: string of upper/lowercase letters, spaces, or hyphens (-).
string must start with an uppercase letter
<middle>?: upper case letter
<last>: string of upper/lowercase letters, spaces, or hyphens (-).
string must start with an uppercase letter
<spouse>? –- first, middle, last are the same type as for employee
<first>
<middle>?
<last>
<child>* -- first, middle, last are the same type as for employee
<first>
<middle>?
<last>
<tax-status> married | single | headOfHousehold | separated
<ssn>: A nine digit number of the form ddd-dd-dddd (e.g, 865-57-2934)
ssn attribute: name=type; values=(assigned | original); default="original"
<salary>: A 9 digit number of the form ddddddd.dd with a minimum value of
0 and a maximum value of 2000000, inclusive.
<date-of-birth>: A date type
<manager> | <staff>
<manager>
attribute for manager: name=title; type=string; use=required
<department>: string
<yrsAtRank>: an inclusive integer between 0 and 50
<staff>
<skill>+: up to 5 skills, each being a string
Here is the XML file:
<?xml version = "1.0"?>
<employeelist:payroll xmlns:employeelist = "urn:myURN:employeelist">
<employee>
<name>
<first>Brad</first>
<middle>T</middle>
<last>Vander Zanden</last>
</name>
<spouse>
<first>Yifan</first>
<last>Tang</last>
</spouse>
<tax-status>married</tax-status>
<ssn type="assigned">186-39-3069</ssn>
<salary>110000.00</salary>
<date-of-birth>1964-02-03</date-of-birth>
<manager title="professor">
<department>Computer Science</department>
<yrsAtRank>8</yrsAtRank>
</manager>
</employee>
<employee>
<name>
<first>Don</first>
<last>Juan</last>
</name>
<child>
<first>Mary</first>
<middle>H</middle>
<last>Lamb</last>
</child>
<child>
<first>Fred</first>
<last>Flintstone</last>
</child>
<tax-status>headOfHousehold</tax-status>
<ssn>586-38-3969</ssn>
<salary>1553.83</salary>
<date-of-birth>1980-07-07</date-of-birth>
<staff>
<skill>Carpentry</skill>
<skill>Welding</skill>
<skill>Plumbing</skill>
</staff>
</employee>
</employeelist:payroll>
And.. here is the XSD (below). I can't find the problem. W3C validator just says: "Markup not well formated." Any clues or thoughts? Thanks in advance!
<?xml version = "1.0"?>
<schema xmlns = "http://www.w3.org/2001/XMLSchema"
xmlns:employeelist = "urn:csc420:employeelist"
targetNamespace = "urn:csc420:employeelist">
<complexType name="employeeType">
<sequence>
<element name="employee" type="employeelist:singleEmployeeType"
minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="nameType">
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<complexType name="spouseType">
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<simpleType name="tax-statusType">
<restriction base = "string">
<enumeration value = "married"/>
<enumeration value = "single"/>
<enumeration value = "headOfHousehold"/>
<enumeration value = "separated"/>
</restriction>
</simpleType>
<simpleType name="ssnType">
<restriction base = "int">
<pattern value = "[0-9]{3}\-[0-9]{2}\-[0-9]{4}"/>
</restriction>
</simpleType>
<simpleType name="salaryType">
<restriction base="decimal">
<minInclusive value="0.00"/>
<maxInclusive value="200000000.00"/>
</restriction>
</simpleType>
<simpleType name="date-of-birthType">
<restriction base="decimal">
<minInclusive value = "0"/>
<maxInclusive value = "10"/>
</restriction>
</simpleType>
<simpleType name="skillType">
<restriction base="decimal">
<minInclusive value = "1"/>
<maxInclusive value="5"/>
</restriction>
</simpleType>
<complexType name="managerType">
<sequence>
<element name="department" type="string"/>
<element name="yrsAtRank" type="int"/>
</sequence>
<attribute name="title" type="string"/>
</complexType>
<complexType name="staffType">
<sequence>
<element name="skill" type="employeelist:skillType"/>
</sequence>
</complexType>
<complexType name="singleEmployeeType">
<sequence>
<element name="name" type="employeelist:nameType"/>
<element name="spouse" type="employeelist:spouseType"/>
<element name="tax-status" type="employeelist:tax-statusType"/>
<element name="ssn" type="employeelist:ssnType"/>
<element name="salary" type="employeelist:salaryType"/>
<element name="date-of-birth" type="date"/>
<element name="manager" type="employeelist:managerType"/>
<element name="staff" type="employeelist:staffType"/>
</sequence>
</complexType>
<element name="payroll" type="employeelist:singleEmployeeType"/>
</schema>
xmlns:andemployeelist. (2) You haveminInclusiveandmaxInclusivedirectly inside asimpleTypeelement, but they need to be contained in arestrictionelement. (3) In your last complexType, you are using the prefixemployeeList(capital L), but the namespace prefix you declared at the top isemployeelist(lower-case L).Invalid content was found starting with element 'employee'. One of '{name}' is expected.Any idea what this could be? Thanks again!