Re: Possible to restrict top-level xs:element names?

I'm not quite sure what you are asking.  Are you trying to restrict how 
your schema can be extended, or are you trying to restrict what is 
allowed in an instance document?  

Perhaps you have a conceptual misunderstanding?  Note that

<xs:schema ...>
   <xs:element name="foo"/>
   <xs:element name="bar"/>
</xs:schema>

is not the same as

<xs:schema ...>
   <xs:choice>
      <xs:element name="foo"/>
      <xs:element name="bar"/>
   </xs:choice>
</xs:schema>

(which isn't legal btw).

That is, the children of your <schema> element do not represent a model 
for your instance documents, which is perhaps how you are thinking of 
it?  Rather, they declare the elements, attributes, and types according 
to which an instance document may be validated.  (Note by the way, that 
there are different approaches to validating documents against schemas, 
see 
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#validation_outcome).

I don't believe you can prevent someone from including your schema 
document into theirs while at the same time adding more global elements, 
if that's what you are trying to avoid.

Kevin

-- 
Objective Systems, Inc.
REAL WORLD ASN.1 AND XML SOLUTIONS
Tel: +1 (484) 875-9841
Fax: +1 (484) 875-9830
Toll-free: (877) 307-6855 (USA only)
http://www.obj-sys.com



On 11/6/2009 1:58 AM, kennardconsulting wrote:
> Hi guys,
>
> I'm generating a bunch of XML Schemas that look roughly like:
>
> <xs:schema ...>
>    <xs:element name="foo"/>
>    <xs:element name="bar"/>
> </xs:schema>
>
> You can see the actual ones  http://metawidget.org/xsd here . My question
> is, this schema allows me to declare 'foo' and 'bar' in my XML document, but
> doesn't restrict me declaring, say, 'baz'. I was expecting something like...
>
> <xs:schema final="#all">
>
> ....so that I could 'close' the set of possible xs:element names. Or maybe
> that the set was closed by default and I'd need...
>
> <xs:schema ...>
>    <xs:element name="foo"/>
>    <xs:element name="bar"/>
>    <xs:any />
> </xs:schema>
>
> ....to make it open. But instead the set of top-level xs:element names
> appears 'open' by default and I can't find a way to close it? I have looked
> all over the specs and in this forum, sorry if I'm being dumb.
>
> Regards,
>
> Richard.
>   

Received on Friday, 6 November 2009 19:32:40 UTC