0

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>
4
  • Even if you are embarrassed, you should provide what you have so far. StackOverflow isn't a free XSD-writing service. Commented Jan 31, 2014 at 7:12
  • @JLRishe JL, I added my code, do you happen to see any syntax or logical issues at first glance? Thanks. Commented Jan 31, 2014 at 7:53
  • Your XSD is currently invalid for three reasons: (1) You have a space between xmlns: and employeelist. (2) You have minInclusive and maxInclusive directly inside a simpleType element, but they need to be contained in a restriction element. (3) In your last complexType, you are using the prefix employeeList (capital L), but the namespace prefix you declared at the top is employeelist (lower-case L). Commented Jan 31, 2014 at 8:08
  • @JLRishe, I have fixed all supposed issues according to W3C validator, expect for one last error message on line 4: Invalid content was found starting with element 'employee'. One of '{name}' is expected. Any idea what this could be? Thanks again! Commented Jan 31, 2014 at 8:50

1 Answer 1

1

You have defined the type for "payroll" to be a "singleEmployeeType" so it expects the elements of a single employee (name, spouse etc.) directly inside the <payroll> element. That doesn't match your input XML and it doesn't look like you intended it.

Just change the definition of the payroll element in your XSD to:

<element name="payroll" type="employeelist:employeeType"/>

In your XSD, you defined employeeType to be a 1 or more <employee> elements. I suggest that you fix the naming of types in your XSD to be consistent with whether its accepts only one or more of something. Whatever convention you like is fine, as long as its consistent. You could rename employeeType to employeesType or employeeListType as long as you use 'plural' or 'add List' convention consistently.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.