Include statement, it drives me nuts!

K

Karl

Hi!

I'm trying with a really simple test, to use a schema within another, but
xmlspy keeps giving me error message: Schema Error - undefined value for
'type' encountered!

The file PersonGroup.xsd refuses to validate the Person type, even though
the include element. I know it finds the Person.xsd file, because I get a
"not found" error if I change the schemaLocation value. I thought I was
doing everything by the book, I just cant find the mistake!

It is as simple as this:

File: Person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.test.com/schemas"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test.com/schemas" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Phonenumber" type="xs:string"/>
<xs:element name="Firstname" type="xs:string"/>
<xs:element name="Lastname" type="xs:string"/>
</xs:sequence>
<xs:attribute name="Id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

File: PersonGroup.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.test.com/schemas"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test.com/schemas" elementFormDefault="qualified">
<xs:include schemaLocation="Person.xsd"/>
<xs:element name="PersonGroup">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Name"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="aPerson" type="Person" />
<xs:element name="PersonId" type="xs:IDREF"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

regards

Karl Z
 
P

Priscilla Walmsley

Hi,

The "type" attribute has to refer to a type (complex or simple). Your
"Person" defined in the included schema is an element, not a type. You
should either change it to:

element ref="Person"

or make Person a complex type rather than an element.

Hope that helps,
Priscilla
 
K

Karl

Hi again!

Yes, it helped, now I can reference the schemas from each other!

Unfortunately, I got another very strange problem, when I try to use the
simple schema, person.xsd.

Xmlspy gives me "No content model available for validation (possible empty
DTD/Schema)", in the Person.xsd when I try to save my test.xml file, which
is very simple indeed:

Test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="http://www.test.com/schemas"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.test.com/schemas
C:\vcs\Source\Import_export_formats\Schemas\Person.xsd">
</Person>

Person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.test.com/schemas"
xmlns="http://www.test.com/schemas"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:complexType name="Person">
<xs:sequence>
<xs:element name="Phonenumber" type="xs:string"/>
<xs:element name="Firstname" type="xs:string"/>
<xs:element name="Lastname" type="xs:string"/>
</xs:sequence>
<xs:attribute name="Id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:schema>

Is there something obvious I've missed?

regards

Karl Z
 
P

Priscilla Walmsley

Hi,

Yes, you do also need to have an element named Person. In the first
example you gave me, the Person element was declared in your other
schema. In this case, the Person element is not declared anywhere.

If you add:

<xs:element name="Person" type="Person"/>

it should work.

Priscilla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top