469,283 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

The referenced element is undefined

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>
Jul 20 '05 #1
4 2999
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

-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
Priscilla Walmsley wrote:
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/developerwork...tml?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">
Jul 20 '05 #3
> So the schema (Listing 2) at
http://www-106.ibm.com/developerwork...2.html?ca=dnt-
520isn't valid at all?


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
-----------------------------------------------------
Priscilla Walmsley pr*******@walmsley.com
Author, Definitive XML Schema (Prentice Hall PTR)
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Priscilla Walmsley wrote:
If you show me your whole schema I can probably explain better...


Got it working thanks. Watch out for another posting of mine :-)
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Razzbar | last post: by
6 posts views Thread by Luke Dalessandro | last post: by
1 post views Thread by jason.lucey | last post: by
10 posts views Thread by rush2 | last post: by
4 posts views Thread by sjkothenbeutel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.