[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Problem w/ Schema for elements with similar defs
I am trying to write an XML Schema to support the following problem: Let's say I have the following xml instance to represent a set of objects named "pantalla". --------------- <pantallas xmlns="http://www.telenium.es/XML" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.telenium.es/XML pantallas.xsd"> <pantalla nombre="Prueba"> <parametros> <parametro nombre="p1"/> </parametros> <dimensiones x="100" y="100"/> <consulta valor="titulo"> <texto nombre="T1" ancho="40" alto="10"/> </consulta> <recurso valor="boton"> <texto nombre="B1" ancho="20" alto="20"/> </recurso> <consulta valor="foto"> <imagen nombre="F1" ancho="100" alto="40" x="10" y="80"/> </consulta> </pantalla> </pantallas> --------------- 1. "pantallas" has 0 or more "pantalla" in it. 2. Every "pantalla" has an attribute "nombre" (required) 3. Every "pantalla" has a prologue made of a set of elements like "parametros" or "dimensiones". 3.1. "parametros" can appear only once (for a given "pantalla"), but it's optional 3.2. "dimensiones" is required 4. Every "pantalla" has a rest of the content. It is made of elements "consulta" or "recurso" in any order and number. 5. "consulta" and "recurso" have some common characteristics: 5.1. Both have an attribute called "valor" 5.2. Both can content an element "texto" 5.3. Only "consulta" can content an element "imagen" 6. "texto" and "consulta" have a common set of attributes: "nombre", "ancho" and "alto" I've tried the following XSD but unsuccesfully because I've not been able to write the rules for (4) and (5.3): --------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <xsd:schema targetNamespace="http://www.telenium.es/XML" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns="http://www.telenium.es/XML" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="pantallas"> <xsd:complexType> <xsd:sequence> <xsd:element ref="pantalla" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="pantalla"> <xsd:complexType> <xsd:sequence> <xsd:element ref="parametros" minOccurs="0" maxOccurs="1"/> <xsd:element ref="dimensiones" minOccurs="1" maxOccurs="1"/> <xsd:element name="consulta" type="consultaTipo" minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="recurso" type="consultaTipo" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="nombre"/> </xsd:complexType> </xsd:element> <xsd:element name="parametros"> <xsd:complexType> <xsd:sequence> <xsd:element name="parametro" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="nombre" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="dimensiones"> <xsd:complexType> <xsd:attribute name="x" type="xsd:integer"/> <xsd:attribute name="y" type="xsd:integer"/> </xsd:complexType> </xsd:element> <xsd:complexType name="consultaTipo"> <xsd:choice> <xsd:element ref="texto"/> <xsd:element ref="imagen"/> </xsd:choice> <xsd:attribute name="valor"/> </xsd:complexType> <xsd:element name="texto"> <xsd:complexType> <xsd:attributeGroup ref="componenteBasico"/> </xsd:complexType> </xsd:element> <xsd:element name="imagen"> <xsd:complexType> <xsd:attributeGroup ref="componenteBasico"/> <xsd:attribute name="x" type="xsd:integer"/> <xsd:attribute name="y" type="xsd:integer"/> </xsd:complexType> </xsd:element> <xsd:attributeGroup name="componenteBasico"> <xsd:attribute name="nombre" type="xsd:string"/> <xsd:attribute name="ancho" type="xsd:integer"/> <xsd:attribute name="alto" type="xsd:integer"/> </xsd:attributeGroup> </xsd:schema> --------------------- I'll be extremely grateful for your help. And just in case... I wish you a very good New Year. Best Regards, José Manuel Beas -- José Manuel Beas (jmbeas@t...) Software Engineer TELENIUM, The New Millennium Telecom Company Agustín de Foxá, 25, plta. 13 28036 MADRID Tel. +34 91 315 85 62 (ext. 260) Fax +34 91 315 63 37 http://www.telenium.es
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|