XML Schema unordered list

Steve Beech <[email protected]> Thu, 14 Aug 2003 15:04:31 +0100
Newsgroups gmane.comp.java.sun.xml.general
Message-ID <[email protected]>
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C3626C.FBD92D50
Content-Type: text/plain;
        charset="big5"

Hi All,

I have an XML doc which has some optional elements. I need to create a
schema to validate this document.

My XML dox example is shown below:

<resource>
    <subject>economics</subject>
    <name>econores</name>
    <summary>an economics resource</summary>
    <location>somewhere</location>
    <resource_type>sometype</resource_type>
    <keyword>economics</keyword>
    <icon>no icon</icon>
    <admin>xy54w</admin>
    <result>x</result>
    <partialResults>hhhhhh</partialResults>
    <diagnostic xmlns=" http://www.some.co.uk/diagnostic
<http://www.some.co.uk/diagnostic> ">Theres something wrong</diagnostic>
</resource>

What I need to allow is any of the first 9 elements to appear 0 to many
times in any order, and the final element to appear 0 or 1 times, but always
at the end.

I've tried the following schema definition, but this just insists that all
elements are present. Can anyone help me ??!?!

 <xs:element name="resource">
        <xs:complexType>
            <xs:sequence maxOccurs="1" minOccurs="0">
                <xs:sequence maxOccurs="unbounded" minOccurs="1">
                    <xs:choice>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="subject"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="name"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
name="summary" type="xs:string"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="location"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="resource_type"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="keyword"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="icon"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="admin"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0"
ref="result"/>
                        <xs:element maxOccurs="1" minOccurs="0"
ref="partialResults"/>
                    </xs:choice>
                </xs:sequence>
                <xs:any namespace=" http://www.some.co.uk/diagnostic"/
<http://www.some.co.uk/diagnostic> >
            </xs:sequence>
              <xs:anyAttribute namespace="
http://www.angel.ac.uk/diagnostic"/ <http://www.angel.ac.uk/diagnostic> >
        </xs:complexType>
    </xs:element>

Thanks in advance.

Steve

-----------------------------------------------------
xml-interest: A list for discussing XML technologies in the Java Platform.
To post, mailto:[email protected]
Archives at: http://archives.java.sun.com/xml-interest.html
To unsubscribe, mailto:[email protected] the following message;
signoff xml-interest.

------_=_NextPart_001_01C3626C.FBD92D50
Content-Type: text/html;
        charset="big5"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">


<META content="MSHTML 6.00.2800.1170" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>Hi
All,</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>I have
an XML doc which has some optional elements. I need to create a schema to
validate this document.</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>My XML
dox example is shown below:</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2>&lt;resource&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff
size=2>&lt;subject&gt;economics&lt;/subject&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;name&gt;econores&lt;/name&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;summary&gt;an economics
resource&lt;/summary&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff
size=2>&lt;location&gt;somewhere&lt;/location&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff
size=2>&lt;resource_type&gt;sometype&lt;/resource_type&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2>&nbsp;&nbsp;&nbsp;
&lt;keyword&gt;economics&lt;/keyword&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;icon&gt;no icon&lt;/icon&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;admin&gt;xy54w&lt;/admin&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;result&gt;x&lt;/result&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff
size=2>&lt;partialResults&gt;hhhhhh&lt;/partialResults&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003>&nbsp;&nbsp;&nbsp; <FONT face=Arial
color=#0000ff size=2>&lt;diagnostic xmlns="<A
href="http://www.some.co.uk/diagnostic">http://www.some.co.uk/diagnostic</A>"&gt;Theres
something wrong&lt;/diagnostic&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2>&lt;/resource&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>What I
need to allow is any of the first 9 elements to appear 0 to many times in any
order, and the final element to appear 0 or 1 times, but always at the
end.</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>I've
tried the following schema definition, but this just insists that all elements
are present. Can anyone help me ??!?!</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2>&nbsp;&lt;xs:element
name="resource"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:complexType&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:sequence maxOccurs="1"
minOccurs="0"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:sequence maxOccurs="unbounded"
minOccurs="1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:choice&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="subject"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="name"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0" name="summary"
type="xs:string"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="location"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="resource_type"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="keyword"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="icon"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="admin"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="unbounded" minOccurs="0"
ref="result"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element maxOccurs="1" minOccurs="0"
ref="partialResults"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:choice&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:sequence&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:any namespace="<A
href='http://www.some.co.uk/diagnostic"/'>http://www.some.co.uk/diagnostic"/</A>&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:sequence&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:anyAttribute namespace="<A
href='http://www.angel.ac.uk/diagnostic"/'>http://www.angel.ac.uk/diagnostic"/</A>&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:complexType&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/xs:element&gt;<BR>&nbsp;
</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff size=2>Thanks
in advance.</FONT></SPAN></DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=002040214-14082003><FONT face=Arial color=#0000ff
size=2>Steve</FONT></SPAN></DIV></BODY></HTML>
-----------------------------------------------------
xml-interest: A list for discussing XML technologies in the Java Platform.
To post, mailto:[email protected]
Archives at: http://archives.java.sun.com/xml-interest.html
To unsubscribe, mailto:[email protected] the following message;
signoff xml-interest.

------_=_NextPart_001_01C3626C.FBD92D50--