W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2006

Re: anonymous element

From: George Cristian Bina <george@oxygenxml.com>
Date: Sat, 02 Dec 2006 08:47:49 +0200
Message-ID: <45712195.2080500@oxygenxml.com>
To: "Kassahun, Ayalew" <Ayalew.Kassahun@wur.nl>
CC: xmlschema-dev@w3.org

Hi,

You cannot do that in XML Schema. It does not work like that. Even if 
you use xs:any, you do not define elements with it, you can use it only 
to make a reference to other element definitions. The only thing that 
defines an element and specifies its content is xs:element with a name 
attribute.

What you want can be expressed with Relax NG as Relax NG allows to 
specify the content for a whole class of elements or attributes, see 
below a schema that does exactly what you asked for:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
     <start>
         <ref name="any"/>
     </start>
     <define name="any">
         <element>
             <anyName/>
             <attribute name="id"/>
             <attribute name="name"/>
             <zeroOrMore>
                 <choice>
                     <attribute>
                         <anyName>
                             <except>
                                 <choice>
                                     <name>id</name>
                                     <name>name</name>
                                 </choice>
                             </except>
                         </anyName>
                     </attribute>
                     <text/>
                     <ref name="any"/>
                 </choice>
             </zeroOrMore>
         </element>
     </define>
</grammar>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Kassahun, Ayalew wrote:
> Hi;
> 
>  
> 
> How can I define anonymous elements (elements without names) in XML schema?
> 
>  
> 
> What I would like to achieve is a schema in which the following 
> statements are true:
> 
> 1.       An XML document based on the schema can contain any XML element.
> 
> 2.       All XML elements should have “id” and “name” attributes.
> 
>  
> 
> In short something like this:
> 
>  
> 
> <xsd:schema targetNamespace="http://www.bla" 
> xmlns:xsd=http://www.w3.org/2001/XMLSchema>
> 
>     <!-- anonymous element  -->
> 
>     <xsd:complexType name="Anonymous.Type">
> 
>         <xsd:attribute name="id" type="xsd:string"/>
> 
>         <xsd:attribute name="name" type="xsd:string"/>
> 
>     </xsd:complexType>
> 
>  
> 
>      <xsd:element name="*" type=" Anonymous.Type"/>
> 
> </xsd:schema>
> 
>  
> 
> Assuming “*” indicates an “anonymous element”, but such a thing doesn’t 
> exist in Schema definition.
> 
>  
> 
> How do I achieve this?
> 
>  
> 
> Regards;
> 
> *Ayalew*
> 
>  
> 
Received on Saturday, 2 December 2006 06:48:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:56 GMT