Validate filename

Questions about XML that are not covered by the other forums should go here.
xephon
Posts: 95
Location: Hamburg/Germany

Validate filename

Tue Jul 21, 2015 2:11 pm

Hi,

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

Best regards,
Stefan
Join the DOCTALES DITA development team :arrow: https://doctales.atlassian.net/wiki
xephon
Posts: 95
Location: Hamburg/Germany

Re: Validate filename

Fri Jul 24, 2015 2:13 pm

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>
Join the DOCTALES DITA development team :arrow: https://doctales.atlassian.net/wiki
tavy
Posts: 123

Re: Validate filename

Mon Jul 27, 2015 11:44 am

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/17.0/ug-editor/index.html#tasks/create-validation-scenario.html

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
xephon
Posts: 95
Location: Hamburg/Germany

Re: Validate filename

Fri Jul 31, 2015 11:04 am

Thank you, Octavian. That's great news!

Greetings,
Stefan
Join the DOCTALES DITA development team :arrow: https://doctales.atlassian.net/wiki
rogerhadley
Posts: 9

Re: Validate filename

Wed Apr 13, 2016 7:04 pm

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

Re: Validate filename

Wed Apr 13, 2016 7:13 pm

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.

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 0 guests