Search code examples
javaregexxmlxsdglob

Wildcard file matching in XML


XML file contains <Wildcard> tag,

       <Wildcard>r_prior*.obj</Wildcard>

I want to access file with name r_prior[0-9].obj , there can be a file r_prior_dummy.obj (which I dont need), but with current code it's taking r_ram_dummy.obj also.

Schema code for <Wildcard> :

    <simpleType name="Wildcard">
      <restriction base="string">
        <pattern value="[^\\/]+"></pattern>
      </restriction>
    </simpleType>

I tried putting <Wildcard>r_prior[0-9].obj</Wildcard>, but it does not work.

How should I do this?


Solution

  • There appear to be two independent types of pattern matching in play here:

    • Regular expressions: What XML Schema uses in xs:pattern. More expressive than file globbing; uses * to match zero or more of the preceding character; ? to match the preceding character optionally; and many more matching constructs.
    • File globbing: What libraries often use for filtering lists of files. Typically less expressive than regular expressions; uses * to match any character; ? to match exactly one unknown character (in some cases includes 0 unknown characters); etc.

    Assuming that you can only change the XML file, you need to check the Java app to see what type of file globbing constructs it supports. (If you have the source, see what call is being made to filter the list of files and check its documentation.) You can assume that * is supported. You cannot assume that [characters] is supported, for example.