Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to restrict a string to be ASCII only in XSD?

Tags:

xsd

Although the XML file being described by the XSD Schema may contain any unicode characters in general, there are some fields where only ASCII is allowed. (As these strings are going to be passed to another system which only accepts ASCII.)

Is there a way to specify that in XSD?

A regexp with all possible ASCII characters would be a possibility I suppose, but I feel there must be a better way.

like image 996
Adrian Smith Avatar asked Feb 22 '23 02:02

Adrian Smith


2 Answers

You can try that :

<xs:simpleType name="basicLatin">
    <xs:restriction base="xs:string">
        <xs:pattern value="\p{IsBasicLatin}*"/>
    </xs:restriction>
</xs:simpleType>
like image 84
Vincent Biragnet Avatar answered May 09 '23 22:05

Vincent Biragnet


Unfortunately, for your requirement there isn't a way to restrict without using patterns.

like image 26
Petru Gardea Avatar answered May 09 '23 20:05

Petru Gardea