modules with spaces in pathnames in .NET?

2012-02-20
2012-10-08
  • Phil Pfeiffer

    Phil Pfeiffer - 2012-02-20

    I'm using the .NET version of Saxon 9.4.0.1 EE. I'm trying to write a query
    that imports a file in the current directory. To do this, I've tried to use
    the statement

    import module
    namespace date-functions = "http://www.cs.etsu.edu/xquery-training-assignment
    /time-functions/0.1
    "
    at "date-functions.xql";

    When I run my query using the Windows command prompt -- i.e., a command like

    xquery -s:datafile.xml -q:query.xql

    I get the following error message:

    Error on line 7 column 1 of 06%20starter%20date%20check%20query.xql:
    Invalid location URI file:///E:/phil/classes-ETSU/csci4617/assign/assign
    04/date-functions.xql: Illegal character in path at index 51:
    file:///E:/phil/classes-ETSU/csci4617/assign/assign 04/date-functions.xql

    The illegal character is obviously the space in the directory name "assign
    04". While copying the relevant files to assign 04's parent directory and
    rerunning the query works around the problem, I'd like to know for my
    students' sake as well as mine if there are any ways of accessing a file along
    a directory path that has spaces in the path.

    For what it's worth, I've tried writing

    import module
    namespace date-functions = "http://www.cs.etsu.edu/xquery-training-assignment
    /time-functions/0.1
    "
    at "file:///E:/phil/classes-ETSU/csci4617/assign/assign%2004/date-
    functions.xql";

    That version of the query generates the very same error message.

    I've also tried escaping the escape character-- i.e., writing %%20 for space--
    which only makes things worse.

    Am I missing a hack that will allow me to access files whose pathnames include
    spaces?

     
  • Michael Kay

    Michael Kay - 2012-02-20

    A quick test shows that this is working for me under Java on the Mac. Saxon
    obtains the base URI of the main query using File.toURI(), which substitutes
    %20 for the space when forming the base URI, and this then allows the relative
    URI to be resolved correctly. The code being executed under .NET is exactly
    the same, but I'll have to step into it to see why it's behaving differently.
    in case you're able to get to it before I do, try (a) calling static-base-
    uri() in the main query to see whether the %HH encoding has been done, (b) try
    a call on resolve-uri() to see whether a relative reference can be resolved
    against that URI, and (c) try a call on doc() to see whether the result of
    calling resolve-uri() can be dereferenced.

    Alternatively, if you want to make progress, steer clear of this minefield by
    avoiding spaces or other special characters in filenames... One of the
    problems is that the rules for converting URIs to filenames are platform-
    specific and in many cases very poorly specified.

     
  • Phil Pfeiffer

    Phil Pfeiffer - 2012-02-21

    Thanks as ever for the quick response, Mr. Kay. It's very much appreciated. As
    per your suggestion, I just ran some tests on static-base-uri() and resolve-
    uri(). The results were as follows:

    -. static-base-uri() succeeded
    -. resolve-uri() failed
    -. since resolve-uri() failed, testing doc(resolve-uri()) seemed pointless.

    I also ran tests on encode-for-uri(), doc-available(), doc(), and base-uri().
    All
    seemed to work just fine.

    For what it's worth, here's my test document, test.xml:

    <test/>

    All queries were run from within a directory, 'assign 04', that has a space in
    its name.

    Finally, here's the actual output from my test script, runtests.bat:

    E:\phil\classes-ETSU\csci4617\assign\assign 04>runtests.bat

    #### static-base-uri() ##########

    E:\phil\classes-ETSU\csci4617\assign\assign 04>more static-base-uri.xql
    declare default element namespace "";
    declare option saxon:output "omit-xml-declaration=yes";
    static-base-uri(), ' '

    E:\phil\classes-ETSU\csci4617\assign\assign 04>xquery -q:static-base-uri.xql
    file:/E:/phil/classes-ETSU/csci4617/assign/assign%2004/static-base-uri.xql

    #### resolve-uri('test.xml', base-uri(doc())) ##########

    ++++++++++ relative path ++++++++++

    E:\phil\classes-ETSU\csci4617\assign\assign 04>more resolve-uri-doc-relative-
    path.xql
    declare default element namespace "";
    declare option saxon:output "omit-xml-declaration=yes";
    resolve-uri('test.xml', base-uri(doc('test.xml'))), ' '

    E:\phil\classes-ETSU\csci4617\assign\assign 04>xquery -q:resolve-uri-doc-
    relative-path.xql
    Error on line 3 of resolve-uri-doc-relative-path.xql:
    FORG0002: Base URI {file:///E:/phil/classes-ETSU/c...} is invalid: Illegal
    character in
    path at index 51: file:///E:/phil/classes-ETSU/csci4617/assign/assign
    04/test.xml
    Query processing failed: Run-time errors were reported

    ++++++++++ absolute path, unix slashes ++++++++++

    E:\phil\classes-ETSU\csci4617\assign\assign 04>more resolve-uri-doc-absolute-
    path-unescaped-unix-slashes.xql
    declare default element namespace "";
    declare option saxon:output "omit-xml-declaration=yes";
    resolve-uri('test.xml', base-uri(doc('E:/phil/classes-
    ETSU/csci4617/assign/assign 04/test.xml'))), ' '

    E:\phil\classes-ETSU\csci4617\assign\assign 04>xquery -q:resolve-uri-doc-
    absolute-path-unescaped-unix-slashes.xql
    Error on line 3 of resolve-uri-doc-absolute-path-unescaped-unix-slashes.xql:
    FORG0002: Base URI {file:///E:/phil/classes-ETSU/c...} is invalid: Illegal
    character in
    path at index 51: file:///E:/phil/classes-ETSU/csci4617/assign/assign
    04/test.xml
    Query processing failed: Run-time errors were reported

    ++++++++++ absolute path, windows slashes ++++++++++

    E:\phil\classes-ETSU\csci4617\assign\assign 04>more resolve-uri-doc-absolute-
    path-unescaped-windows-slashes.xql
    declare default element namespace "";
    declare option saxon:output "omit-xml-declaration=yes";
    resolve-uri('test.xml', base-uri(doc('E:\phil\classes-
    ETSU\csci4617\assign\assign 04\test.xml'))), ' '

    E:\phil\classes-ETSU\csci4617\assign\assign 04>xquery -q:resolve-uri-doc-
    absolute-path-unescaped-windows-slashes.xql
    Error on line 3 of resolve-uri-doc-absolute-path-unescaped-windows-
    slashes.xql:
    FORG0002: Base URI {file:///E:/phil/classes-ETSU/c...} is invalid: Illegal
    character in
    path at index 51: file:///E:/phil/classes-ETSU/csci4617/assign/assign
    04/test.xml
    Query processing failed: Run-time errors were reported

    E:\phil\classes-ETSU\csci4617\assign\assign 04>

     
  • Michael Kay

    Michael Kay - 2012-02-22

    We've found the bug and recorded it here:

    http://dev.saxonica.com/community/issues/1416

    The solution will find its way into the next maintenance release, which should
    be in the next few days.

     
  • Phil Pfeiffer

    Phil Pfeiffer - 2012-02-23

    Thank you for listening; it's very much appreciated -- something I'll share
    with my students, as soon as I can check your post out (I'm currently having
    no luck with connecting to dev.saxonica.com, dev.saxonica.com/community,
    dev.saxonica.com/community/issues, dev.saxonica.com/community/issues/1416,
    79.170.198.133, 79.170.198.133/community, 79.170.198.133/community/issues, or
    79.170.198.133/community/issues/1416.)

    Respect and regards,

    -- Phil

     
  • Michael Kay

    Michael Kay - 2012-02-23

    Apologies for the interruption of service on the dev.saxonica.com site. It's a
    commercial problem which we're trying to get resolved as a matter of urgency -
    our payments to the service provider seem to have not been registered in their
    system.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks