validaciones vacio lista extension elementos elemento ejemplo con atributos archivo attributes xsd restriction

attributes - vacio - Restricción de XSD en el atributo



xsd con xml (2)

Lo siguiente debería funcionar

<element name="umbrella" nillable="true" type="umbrellaType">

<complexType name="umbrellaType"> <attribute name="color"> <simpleType> <restriction base="int"> <minExclusive value="99"></minExclusive> <maxInclusive value="999"></maxInclusive> </restriction> </simpleType> </attribute> </complexType>

Creo que he buscado mucho sobre esto, pero todavía no he ido.

Apreciaré cualquier ayuda.

Estoy tratando de restringir un atributo para un elemento con contenido vacío. "color" debe tener una restricción para mantener solo 3 dígitos o minLength = 3 y maxLength = 3. No debe tener ningún contenido.

<?xml version="1.0" encoding="utf-8"?> <items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=""> <product id="" name=""> <article id="1001"> <umbrella color="100"/> <umbrella color="101"/> </article> <article id="1002"> <umbrella color="110"/> </article> </product> </items>

EDITAR: Sé cómo hacer una restricción XSD en un simpleType. Pero no sé cómo combinarlo en una entidad con un ComplexType.

Si pudiera proporcionar una solución más detallada (o completa), estaría feliz.

Por cierto, "color" no se limita a xs: integer. En realidad es un xs: string.


Puede definir su atributo similar al siguiente. Este ejemplo utiliza un patrón para restringir el valor, pero también podría usar min y max si eso es más apropiado.

<xs:attribute name="color"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:pattern value="[0-9][0-9][0-9]"/> </xs:restriction> </xs:simpleType> </xs:attribute>

Luego, en la definición de su elemento, simplemente use una ref para hacer referencia al atributo definido:

<xs:attribute ref="color"/>

ACTUALIZACIÓN (en respuesta al comentario de OP):

Aquí es cómo se vería todo el esquema:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:attribute name="color"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:pattern value="[0-9][0-9][0-9]"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="id"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:pattern value="[0-9][0-9][0-9][0-9]"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="name" type="xs:string"/> <xs:complexType name="article_type"> <xs:attribute ref="color" use="required"/> </xs:complexType> <xs:element name="article"> <xs:complexType> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element name="umbrella" type="article_type"/> </xs:choice> <xs:attribute ref="id" use="required"/> </xs:complexType> </xs:element> <xs:element name="product"> <xs:complexType> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element ref="article"/> </xs:choice> <xs:attribute ref="id" use="required"/> <xs:attribute ref="name"/> </xs:complexType> </xs:element> <xs:element name="items"> <xs:complexType> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element ref="product"/> </xs:choice> </xs:complexType> </xs:element> </xs:schema>