We help IT Professionals succeed at work.

Can't get my xml file to validate against my xsd

toymachiner62
on
274 Views
Last Modified: 2008-07-16
Newbie question here. I have an xml file and im trying to create an xsd for it and i keep getting the error "expecting element schema, got courses." my xsd and xml file are in the same directory. Any suggestions?
***************************************************
.xml file
****************************************************
 
<?xml version="1.0" encoding="UTF-8"?>
 
<courses xmlns = "http://www.homework2.com/targetNamespace"
xmlns:xsi = "homework2xsd.xsd"
xsi:schemaLocation = "homework2xsd.xsd">
 
 <course number = "CS341" credits = "4.0">
    <title>Data Structures</title>
    <section number = "01" id = "X001780" delivery = "Classroom">
      <enrollment>4</enrollment>
      <date>
        <start_date>08/26/2008</start_date>
        <end_date>12/11/2008</end_date>
      </date>
      <days>T TH</days>
      <time>
        <start_time>4:00pm </start_time>
        <end_time>5:50pm</end_time>
      </time>
      <room campus = "Rochester">EA244</room>
      <instructor>
        <first>Nicole</first>
        <last>Anderson</last>
      </instructor>
	  </section>
	  <section number = "CS341" id = "X001788" delivery = "On-line">
      <enrollment>0</enrollment>
      <date>
        <start_date>08/29/2008</start_date>
        <end_date>12/12/2008</end_date>
      </date>
      <days></days>
      <time>
        <start_time></start_time>
        <end_time></end_time>
      </time>
      <room campus = "Rochester"></room>
      <instructor>
        <first>Nicole</first>
        <last>Anderson</last>
      </instructor>
      <instructor>
        <first>Chi-Cheng</first>
        <last>Lin</last>
      </instructor>
	  </section>
  </course>
  <course number = "CS368" credits = "3.0">
    <title>Introduction to Bioinformatics</title>
    <section number = "01" id = "X001781" delivery = "ITV">
      <enrollment>3</enrollment>
      <date>
        <start_date>08/27/2008</start_date>
        <end_date>12/10/2008</end_date>
      </date>
      <days>W</days>
      <time>
        <start_time>6:00pm </start_time>
        <end_time>8:40pm</end_time>
      </time>
      <room campus = "Rochester">AT102</room>
      <instructor>
        <first>Chi-Cheng</first>
        <last>Lin</last>
      </instructor>
      <instructor>
        <first>Mingrui</first>
        <last>Zhang</last>
      </instructor>
	    </section>
    </course>
  <course number = "CS375" credits = "4.0">
    <title>Computer Systems</title>
    <section number = "01" id = "X001782" delivery = "Classroom">
     <enrollment>12</enrollment>
     <date>
       <start_date>08/25/2008</start_date>
       <end_date>12/10/2008</end_date>
     </date>
     <days>M W</days>
     <time>
       <start_time>4:00pm </start_time>
       <end_time>5:50pm</end_time>
     </time>
     <room campus = "Rochester">EA244</room>
     <instructor>
       <first>Nicole</first>
       <last>Anderson</last>
     </instructor>
	  </section>
  </course>
  <course number = "CS415" credits = "3.0">
    <title>Principles of Programming Languages</title>
    <section number = "01" id = "X001784" delivery = "Classroom">
      <enrollment>13</enrollment>
      <date>
        <start_date>08/26/2008</start_date>
        <end_date>12/11/2008</end_date>
      </date>
      <days>T TH</days>
      <time>
        <start_time>4:00pm </start_time>
        <end_time>5:20pm</end_time>
      </time>
      <room campus = "Rochester">EA246</room>
      <instructor>
        <first>Hugh</first>
        <last>Ouellette</last>
      </instructor>
	  </section>
  </course>
</courses>
 
********************************************************
.xsd file
********************************************************
 
 
<?xml version="1.0" encoding="UTF-8"?>
 
<schema xmlns = "http://www.homework2.com/defaultns"
xmlns:courses = "http://www.homework2.com/targetNamespace"
targetNamespace = "http://www.homework2.com/targetNamespace"
elementFormDefault="qualified">
 
  <complexType name = "courses">
    <sequence>
      <element name = "course">
        <complexType>
          <sequence>
            <element name = "title" type = "string"/>
            <element name = "section" type = "courses:sectionSub"/>
          </sequence>
        </complexType>
      </element>
    </sequence>
  </complexType>
 
  <group name = "sectionSub">
    <sequence>
      <element name = "enrollment" type = "integer"/>
      <element name = "date"/>
        <sequence>
          <element name = "start_date" type = "string" />
          <element name = "end_date" type = "string" />
        </sequence>
      <element name = "days" type = "string" />
      <element name = "time"/>
        <sequence>
          <element name = "start_time" type = "string"/>
          <element name = "end_time" type = "string"/>
        </sequence>
      <element name = "room">
        <complexType>
          <simpleContent>
            <extension base = "string">
              <attribute name = "campus" type = "string" default = "Rochester"/>
            </extension>
          </simpleContent>
        </complexType>
      </element>
    </sequence>
  </group>
 
  <attributeGroup name = "sectionSubAttributes">
    <attribute name = "number" type = "integer" />
    <attribute name = "id" type = "string"/>
    <attribute name = "delivery" type = "string"/>
  </attributeGroup>
 
 
 
</schema>

Open in new window

Comment
Watch Question

Commented:
you were missing the element tag


 <element name="courses">
  <complexType>
    <sequence>
      <element name = "course">
        <complexType>
          <sequence>
            <element name = "title" type = "string"/>
            <element name = "section" type = "courses:sectionSub"/>
          </sequence>
        </complexType>
      </element>
    </sequence>
  </complexType>
 </element>

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.