- From: Mukul Gandhi <gandhi.mukul@gmail.com>
- Date: Thu, 29 Mar 2018 17:31:18 +0530
- To: www-xml-schema-comments@w3.org
- Message-ID: <CABuuzNMAneB_Z-i9OojqxXPVE4pP+2tCQrGNiPaoP1Yhw7Tt=A@mail.gmail.com>
Hi all, Referring to this thread, https://lists.w3.org/Archives/Public/www-xml-schema-comments/2002OctDec/0003.html a while ago, interestingly I discovered that this is now possible with XSD 1.1 assertions. With assertions we can't specify the attribute 'delimiter' on xsd:list, but we can achieve a very similar effect. Here's an example. The XML document is, <User values="5;6;7" /> And the XSD 1.1 document would be, <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="User"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="values"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:assertion test="every $x in tokenize($value, ';') satisfies (number($x) ge 5) and (number($x) le 7)"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:schema> In this example, each list item should be a number inclusive between 5 & 7. The XPath semantics after 'satisfies' could be anything that each list item should obey. The only drawback I see with this is (at-least with Xerces's XSD 1.1 processor), poorer error diagnostics. The whole assertion is reported as failing, instead of pointing the specific list item that doesn't satisfy the list's itemType specified in this way. -- Regards, Mukul Gandhi
Received on Thursday, 29 March 2018 12:02:03 UTC