Validate filename

Questions about XML that are not covered by the other forums should go here.
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Validate filename

Post by xephon »

Hi,

is it possible to detect forbidden chars in filenames, like '(', ')', 'ä', 'ö', 'ü', etc. with an Oxygen validation scenario?

Best regards,
Stefan
stefan-jung.org – Your DITA/DITA-OT XML consultant
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Validate filename

Post by xephon »

I still do not know, whether it is possible to validate filenames. But now I validate the attribute value of my referring element with Schematron. The result is the same. :wink:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="*">
<report test="contains(@href,'ß')">
Do not use special chars in @href "<value-of select="@href"/>".
</report>
</rule>
</pattern>
</schema>
stefan-jung.org – Your DITA/DITA-OT XML consultant
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Validate filename

Post by tavy »

Hello,

You can validate also the file names using Schematron. To obtain current file name you can use the document-uri() function and then check the characters in the file name. For example you can create a rule like this:

Code: Select all


<rule context="/">
<let name="fileName" value="tokenize(document-uri(/), '/')[last()]"/>
<report test="contains($fileName, encode-for-uri('ß'))">
Do not use special chars in file name "<value-of select="$fileName"/>".
</report>
</rule>
Then you can create a validation scenario and add a new rule that validates you files with the created Schematron. You need to specify your Schematron schema in the "Schema" column from the validation scenario. Read more about how to create a validation scenario in our user manual:
http://www.oxygenxml.com/doc/versions/1 ... nario.html

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Validate filename

Post by xephon »

Thank you, Octavian. That's great news!

Greetings,
Stefan
stefan-jung.org – Your DITA/DITA-OT XML consultant
rogerhadley
Posts: 9
Joined: Tue Aug 21, 2012 11:47 pm

Re: Validate filename

Post by rogerhadley »

document-uri(/) returns the uri of the schematron file, not the file the schematron is validating. How do I get the uri of the file being validated?
rogerhadley
Posts: 9
Joined: Tue Aug 21, 2012 11:47 pm

Re: Validate filename

Post by rogerhadley »

Ah. Never mind. I just figured out my problem. I need to use the fully qualified <sch:*> xpath. Using just <value-of select="$fileName"/> does not work. Using <sch:value-of select="$fileName"/> works.
Post Reply