Saturday, 15 May 2010

xml - XSD definition for simpleType + restriction + anyAttribute -



xml - XSD definition for simpleType + restriction + anyAttribute -

i have simple schema definition simple type:

<xs:simpletype name="std_types-bit-type"> <xs:restriction base="xs:int"> <xs:mininclusive value="0"/> <xs:maxinclusive value="1"/> </xs:restriction> </xs:simpletype>

elsewhere there's:

<xs:element name="comp" type="std_types-bit-type"/>

one can create xml elements this:

<comp>1</comp>

i'd allow document creators add together arbitrary (to me, meaningful them) attributes, such as:

<comp index="2">1</comp>

since can't know possible attributes in advance, xs:anyattribute intended situation. , in fact, defining complextypes straightforward. problem haven't been able find magic combination of schema elements lets me associate xs:anyattribute simpletype/simplecontent restriction.

i can't imagine not possible, it's beating me far.

attributes may added when type derived extension; facets can added type derived restriction. so, allow 2 definitions...

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:simpletype name="std_types-bit-base-type"> <xs:restriction base="xs:int"> <xs:mininclusive value="0"/> <xs:maxinclusive value="1"/> </xs:restriction> </xs:simpletype> <xs:complextype name="std_types-bit-type"> <xs:simplecontent> <xs:extension base="std_types-bit-base-type"> <xs:anyattribute/> </xs:extension> </xs:simplecontent> </xs:complextype> </xs:schema>

xml xsd

No comments:

Post a Comment