Reputation: 57
I am very new to XML and XSD and need a little help. I keep getting this validation error "Element header not allowed for content model (header+, objective*,pubs?). It is appearing at the last line of the XML and I can't figure out what could possibly be causing it. Here is the XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="resume">
<xs:complexType>
<xs:sequence>
<xs:element name="header" minOccurs="1" maxOccurs="unbounded" >
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="NameType" />
<xs:element name="contact" type="ContactType" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="objective" type="ObjectiveType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="pubs" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="pub" type="PubType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="NameType">
<xs:group ref="NameGroup" />
</xs:complexType>
<xs:group name="NameGroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string" />
<xs:element name="middlenames" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="surname" type="xs:string" />
</xs:sequence>
</xs:group>
<xs:complexType name="ContactType">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="phone" type="xs:string" />
<xs:element name="website" type="xs:string" />
<xs:element name="email" type="xs:string" />
<xs:element name="address" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ObjectiveType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="para" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PubType">
<xs:sequence >
<xs:element name="bookTitle" type="xs:string" />
<xs:element name="date" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="month" type="xs:string" />
<xs:element name="year" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="publisher" type="xs:string" />
<xs:element name="url" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
And here is the XML code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<resume xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="A2_Schema_task2.xsd">
<header>
<name>
<firstname>John</firstname>
<middlenames>E.</middlenames>
<surname>Doe</surname>
</name>
<contact>
<email>[email protected]</email>
</contact>
</header>
<objective>
<para>Seeking a position in publishing as Associate Manager</para>
<para>The position will allow me to utilize my experiences to mentor and train my team. </para>
</objective>
<pubs>
<pub>
<bookTitle>Just XML</bookTitle>
<publisher>Wiley</publisher>
<url>http://mycompany/book1</url>
</pub>
<pub>
<bookTitle>XPath and XPointer</bookTitle>
<date><month>August</month><year>2002</year></date>
<publisher>O'Reilly and Associates</publisher>
<url>http://mycompany/book1</url>
</pub>
</pubs>
<header>
<name>
<firstname>Maya</firstname>
<surname>Wells</surname>
</name>
<contact>
<phone>416-785-2598</phone>
</contact>
</header>
<objective>
<para>Seeking a position in publishing as Associate Manager</para>
</objective>
<pubs>
<pub>
<bookTitle>Just JavaScript</bookTitle>
<publisher>Wrox</publisher>
</pub>
</pubs>
<header>
<name>
<firstname>Irene</firstname>
<surname>Mathieu</surname>
</name>
<contact>
<phone>905-785-2598</phone>
<website>www.irenemathieu.com</website>
<email>[email protected]</email>
<address>105 Bathurst Street , Toronto</address>
</contact>
</header>
<objective>
<para>Seeking a position in publishing as Publishing Manager with your company</para>
<para>Seasoned manager offering 30 years of progressive experience as a Publishing Manager, willing to provide advice and leadership for educational publishing in its broadest form.</para>
</objective>
</resume>
Thanks for your help!
Upvotes: 2
Views: 13161
Reputation: 57
Thank you all for your help. I figured out I needed to add a new element (person) that encompasses the header, objective, pubs elements that can be reused for each new person. Here is a sample of what I did to fix the xml and xsd:
xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<resume xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="A2_Schema_task2.xsd">
<person>
<header>
<name>
<firstname>John</firstname>
<middlenames>E.</middlenames>
<surname>Doe</surname>
</name>
<contact>
<email>[email protected]</email>
</contact>
</header>
<objective>
<para>Seeking a position in publishing as Associate Manager</para>
<para>The position will allow me to utilize my experiences to mentor and train my team. </para>
</objective>
<pubs>
<pub>
<bookTitle>Just XML</bookTitle>
<publisher>Wiley</publisher>
<url>http://mycompany/book1</url>
</pub>
<pub>
<bookTitle>XPath and XPointer</bookTitle>
<date><month>August</month><year>2002</year></date>
<publisher>O'Reilly and Associates</publisher>
<url>http://mycompany/book1</url>
</pub>
</pubs>
</person>
and XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="resume">
<xs:complexType>
<xs:sequence>
<xs:element name="person" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="header" >
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="NameType" />
<xs:element name="contact" type="ContactType" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="objective" type="ObjectiveType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="pubs" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="pub" type="PubType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Everything works and validates now. Thank you all for your help!
Upvotes: 0
Reputation: 37103
Your xml is invalid. Your xsd says:
After objective or header, you should have pubs which is again optional which should occur once or none.
In your xml, you have multiple pubs and its of structure:
<header ..>
<objective ...>
<pubs ..>
<header ..>
<objective ...>
<pubs ..>
<header ..>
<objective ...>
Upvotes: 0
Reputation: 771
In you XSD file you defined as first 1..* header, then 0..* objective and finally 0..1 pubs. So your file should looks like:
<resume>
<header>...</header>
<header>...</header>
<header>...</header>
<objective>...</objective>
<objective>...</objective>
<objective>...</objective>
<objective>...</objective>
<pubs>...</pubs>
</resume>
In your XML File you have
<resume>
<header>...</header>
<objective>...</objective>
<pubs>...</pubs>
<header>...</header>
<objective>...</objective>
<pubs>...</pubs>
<header>...</header>
<objective>...</objective>
</resume>
So it's normal that your XML File doesn't validate your XSD File
Upvotes: 2