The referenced element is undefined

T

Timo Nentwig

Hi!

I'm new to XML schemas; can somebody explain why bar is undefined?

<xs:element name="bar">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element ref="bar" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
 
P

Priscilla Walmsley

Hi,

It's probably a namespace issue. If your schema has a target namespace,
you need to either

1. Make that namespace the default namespace, as in:

<xs:schema targetNamespace="xxx" xmlns="xxx" ....

OR

2. Give that namespace a prefix, and use the prefix in the element
reference, as in:

<xs:schema targetNamespace="xxx" xmlns:pre="xxx"
....

<xs:element ref="pre:bar" maxOccurs="unbounded"/>


Hope that helps,
Priscilla
 
T

Timo Nentwig

Priscilla said:
It's probably a namespace issue. If your schema has a target namespace,
you need to either

So the schema (Listing 2) at
http://www-106.ibm.com/developerworks/xml/library/x-pracdb2.html?ca=dnt-520
isn't valid at all?

I actually tried it with an example schema included in the Apache JaxMe
distribution which has this definition:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="EN"
targetNamespace="http://ws.apache.org/jaxme/examples/misc/address"
elementFormDefault="qualified" attributeFormDefault="unqualified">
 
P

Priscilla Walmsley

So the schema (Listing 2) at

No, I said "If your schema has a target namespace". That one's fine
because it doesn't have a target namespace.

The second example you gave me:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="EN"
targetNamespace="http://ws.apache.org/jaxme/examples/misc/address"
elementFormDefault="qualified" attributeFormDefault="unqualified">

Using this schema, because it DOES have a target namespace, you DO need
a namespace declaration for the target namespace BUT ONLY IF you are
planning to reference other components (e.g. element ref="xxx:bar").

If you show me your whole schema I can probably explain better...

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top