PDA

View Full Version : Can not find declaration of element 'syllabus'


Spiral
09-02-2009, 03:29 PM
I have an xml file (SampleSyllabus.xml) with it's associated xml schema (syllabus_schema_1.3.xsd) file. I used DecisionSoft's XML schema validator to validate them. (Link: http://tools.decisionsoft.com/schemaValidate/). Both validate.

The version of SampleSyllabus.xml is shortened. But this file is basically a course syllabus represented in xml. I wanted to select some of the fields from this document, so I created a stylesheet (summary.xsl).

I am using the Eclipse EE IDE with the Xalan processor (2.7.1) to do the XSL transformation. When I go to validate the xml output (SampleOutput.xml) from this transformation... I get the error: Can not find declaration of element 'syllabus'. This error occurs just after the end of the first line in SampleOutput.xml. I used (http://www.validome.org/xml/validate/) to validate my output file.

I am new to XML/XSLT/XSD and I can't seem to figure this error out. Any help/suggestions would be very much appreciated.

I am unable to post all of the schema document. You can find the beginning of the document at the end of this post. (The full xsd document is attached as a txt file.)

SampleSyllabus.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="summary.xsl"?>
<tns:syllabus
xmlns:tns="http://www.example.org/syllabus_schema_1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/syllabus_schema_1.3 syllabus_schema_1.3.xsd">

<courseDetails>
<departmentType>
<dept>CS</dept>
<syllabusLink>http://www.example.org</syllabusLink>
</departmentType>
<title>Introduction to Databases</title>
<level type="undergraduate">
<number>145</number>
</level>
<units>3-4</units>
<duration>quarter</duration>
<universityName>University</universityName>
<collegeName>College</collegeName>
<departmentName>Department</departmentName>
</courseDetails>

<classOffering>
<taughtBy>Dr. Jane Doe</taughtBy>
<readingMaterial refID="1">
<type>required</type>
<title>A First Course in Database Systems</title>
<author>J.D. Ullman</author>
<author>J. Widom</author>
<edition>3</edition>
<publisher>Prentice Hall</publisher>
<datePublished>2008</datePublished>
<ISBN-10>013600637X</ISBN-10>
<ISBN-13>978-0136006374</ISBN-13>
<link>http://www.example.org</link>
</readingMaterial>
<readingMaterial refID="2">
<type>optional</type>
<title>Database Systems: The Complete Book</title>
<author>H. Garcia-Molina</author>
<author>J.D. Ullman</author>
<author>J. Widom</author>
<edition>2</edition>
<publisher>Prentice Hall</publisher>
<datePublished>2008</datePublished>
<link>http://www.example.org</link>
</readingMaterial>
<meetingTime>
<startTime>11:00:00</startTime>
<endTime>12:15:00</endTime>
<timesPerWeek>2</timesPerWeek>
</meetingTime>
<term>Fall</term>
<year>2008</year>
</classOffering>

<gradingDistribution>

</gradingDistribution>

<schedule>
<entry>
<week>0</week>
<topic>
<asListed>Introductory Material</asListed>
</topic>
<lectureNotes>
<ontologyLabel>
<ontologyTerm>Database_Systems</ontologyTerm>
<ontologyPath>L1-Areas/Information_Topics/Database_Systems</ontologyPath></ontologyLabel>
<genre>lecture</genre>
<format>html</format>
<asListed>Introductory Material</asListed>
<link>http://www.example.org</link>
</lectureNotes>
<reading>
<genre>textbook</genre>
<asListed>Chap. 1 all</asListed>
<type>required</type>
<textbook refID="1">
<chapter>1</chapter></textbook>
</reading>
</entry>
</schedule>

</tns:syllabus>


summary.xsl:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:tns="http://www.example.org/syllabus_schema_1.3" version="1.0">
<xsl:output method="xml" indent="yes" xalan:indent-amount="5"/>

<xsl:template match="/tns:syllabus">
<syllabus>
<xsl:for-each select="child::courseDetails/departmentType">
<dept>
<xsl:value-of select="dept"/>
</dept>
</xsl:for-each>
<xsl:for-each select="child::courseDetails/level">
<number>
<xsl:value-of select="number"/>
</number>
<level>
<xsl:value-of select="attribute::type"/>
</level>
</xsl:for-each>
<xsl:for-each select="child::courseDetails">
<title>
<xsl:value-of select="child::title"/>
</title>
</xsl:for-each>
<xsl:for-each select="child::courseDetails/units">
<units>
<xsl:value-of select="."/>
</units>
</xsl:for-each>
<xsl:for-each select="child::courseDetails/creditHours">
<creditHours>
<xsl:value-of select="."/>
</creditHours>
</xsl:for-each>
<xsl:for-each select="child::classOffering/meetingTime">
<timesPerWeek>
<xsl:value-of select="timesPerWeek"/>
</timesPerWeek>
<startTime>
<xsl:value-of select="startTime"/>
</startTime>
<endTime>
<xsl:value-of select="endTime"/>
</endTime>
</xsl:for-each>

<xsl:for-each select="child::schedule/entry">
<entry>
<xsl:for-each select="child::lectureNotes">
<lectureTopic>
<xsl:value-of select="child::asListed"/>
<week>
<xsl:value-of select="ancestor::week"/>
</week>
<xsl:for-each select="child::ontologyLabel">
<ontologyTerm>
<xsl:value-of select="child::ontologyTerm"/>
</ontologyTerm>
<ontologyPath>
<xsl:value-of select="child::ontologyPath"/>
</ontologyPath>
</xsl:for-each>
</lectureTopic>
</xsl:for-each>
</entry>
</xsl:for-each>
</syllabus>
</xsl:template>

</xsl:stylesheet>



SampleOutput.xml:

<?xml version="1.0" encoding="UTF-8"?><syllabus xmlns:tns="http://www.example.org/syllabus_schema_1.3" xmlns:xalan="http://xml.apache.org/xalan">
<dept>CS</dept>
<number>145</number>
<level>undergraduate</level>
<title>Introduction to Databases</title>
<units>3-4</units>
<timesPerWeek>2</timesPerWeek>
<startTime>11:00:00</startTime>
<endTime>12:15:00</endTime>
<entry>
<lectureTopic>Introductory Material<week/>
<ontologyTerm>Database_Systems</ontologyTerm>
<ontologyPath>L1-Areas/Information_Topics/Database_Systems</ontologyPath>
</lectureTopic>
</entry>
</syllabus>


syllabus_schema_1.3.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/syllabus_schema_1.3" xmlns:tns="http://www.example.org/syllabus_schema_1.3">

<annotation>
<documentation>
Course syllabus schema.
</documentation>
</annotation>

<!-- Schema -->
<element name="syllabus" type="tns:syllabusType"/>

<complexType name="syllabusType">
<annotation>
<documentation>
A 'syllabus' has exactly one 'classOffering', exactly one 'courseDetails', exactly one 'schedule' and zero or more 'termsAndMarks'. For each Computing ontology term related to this syllabus, exactly one 'termsAndMarks' exist for it. The 'genre' of a 'syllabus' is either "syllabus" OR "Syllabus".
</documentation>
</annotation>
<sequence>
<element name="courseDetails" type="tns:courseDetailsType"/>
<element name="classOffering" type="tns:classOfferingType"/>
<element name="gradingDistribution" type="tns:gradingDistributionType"/>
<element name="schedule" type="tns:scheduleType"/>
<element name="homework" minOccurs="0" maxOccurs="unbounded" type="tns:homeworkType"/>
<element name="test" minOccurs="0" maxOccurs="unbounded" type="tns:testType"/>
<element name="termsAndMarks" minOccurs="0" maxOccurs="unbounded" type="tns:termsAndMarksType"/>
</sequence>
<attribute name="genre" use="optional">
<simpleType>
<restriction base="string">
<pattern value="[s|S]yllabus"/>
</restriction>
</simpleType>
</attribute>
</complexType>
...