XML schema: duplicate element occurences

  • Thread starter John Jørgensen
  • Start date
J

John Jørgensen

Hi

How do I express - in XSD - that an element can contain a sequenced
list of elements, and one of these elements may occur (0-n times) at
BOTH sequence position x AND y?

Example:
<PRIORITY sorting="900"/>
<NAMEINFO>
subtags and data
</NAMEINFO>
<EXTRA_LINE>
subtags and data
</EXTRA_LINE>
<EXTRA_LINE>
subtags and data
</EXTRA_LINE>
<ADDRINFO>
subtags and data
</ADDRINFO>
<PHONEINFO>
subtags and data
</PHONEINFO>
<EXTRA_LINE>
subtags and data
</EXTRA_LINE>

Currently, my schema looks something like:
<xs:complexType>
<xs:sequence>
<xs:element name="PRIORITY" maxOccurs="1" minOccurs="1">
blablabla
</xs:element>
<xs:element name="NAMEINFO" minOccurs="0">
blablabla
</xs:element>
<xs:element name="LOGO" minOccurs="0">
blablabla
</xs:element>
<xs:element name="EXTRA_LINE" maxOccurs="10" minOccurs="0">
blablabla
</xs:element>
<xs:element name="ADDRINFO">
blablabla
</xs:element>
<xs:element name="PHONEINFO">
blablabla
</xs:element>
<xs:element name="EXTRA_LINE" maxOccurs="10" minOccurs="0">
blablabla
</xs:element>
</xs:complexType>
</xs:element>

Validation says: Duplicated definition for: 'EXTRA_LINE'

I know I can just rename one of my EXTRA_LINE groups or add an extra
level somewhere, but I'm not too keen on that...

Any suggestions?

Regards
/John
 
H

Henry S. Thompson

That's not a very helpful error message, I agree, but _if_ the
blablabla that you have edited out is <xs:complexType>
.. . . </xs:complexType> then there is indeed a problem. You're not
allowed to have the same element with two different type definitions
in the same content model. If your two EXTRA_LINE elements actually
have (textually) the _same_ type definition, move it out to the top
level, give it a name, and change your model above to use

<xs:element name="EXTRA_LINE" ref="[your type]" min=0 max=10/>

and you should be fine.

ht

[1] http://www.w3.org/2001/03/webdata/xsv
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
J

John Jørgensen

The "<xs:element name="EXTRA_LINE" ref="[your type]" min=0 max=10/>"
was excatly what I needed...

Thanks a lot!!!

/John
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top