1

I'm currently creating an XSD file. An XML file according to the XSD should contain an element to capture filenames, e.g. <filename> This is a fancy file with a name that contains spaces + an Ümlaut (and additional challenging characters like brackets and a plus sign).pdf </filename>.

To avoid filenames that will bring typical file systems "into trouble", I'd like to use a suitable restriction for the type of <filename>.

What is a suitable and pragmatic restriction for that type?

<xs:whiteSpace value="collapse" /> is a good start. Obviously this would not prevent linebreaks, forbidden Windows legacy filenames (like CON, PRN etc.), fancy Unicode characters that could break the filename, etc.

So what further restrictions are pragmatic here?

<xs:element name="filename">
    <xs:simpleType>
        <xs:restriction base="xs:string"> <!-- what to use as base? -->
            <xs:whiteSpace value="collapse" />
            <!-- how to further restrict here? -->
        </xs:restriction>
    </xs:simpleType>
</xs:element>
Hauke P.
  • 2,695
  • 1
  • 20
  • 43
  • Just thought about this a little more: `````` is actually *not* a good solution since this would replace succeeding spaces with only one space. Therfore, you would not be able to distinguish between ```a b.pdf``` and ```a   b.pdf``` anymore. – Hauke P. Aug 09 '19 at 08:14
  • Use a regex expression like https://stackoverflow.com/questions/6768779/test-filename-with-regular-expression – Dijkgraaf Aug 14 '19 at 02:51

0 Answers0