4

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.

Adrian Smith
  • 17,236
  • 11
  • 71
  • 93
  • 1
    All ASCII characters? Even control codes? Or a subset of ASCII? – skaffman Mar 20 '12 at 17:10
  • a regex i found (and which i use) is ``[ -~]`` everything between space and tilde. https://stackoverflow.com/a/24903178/25286 – GDmac Dec 19 '22 at 12:11

2 Answers2

6

You can try that :

<xs:simpleType name="basicLatin">
    <xs:restriction base="xs:string">
        <xs:pattern value="\p{IsBasicLatin}*"/>
    </xs:restriction>
</xs:simpleType>
Vincent Biragnet
  • 2,950
  • 15
  • 22
2

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

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62