eXist-DB / XQuery StringValue cannot be cast to AnyURIValue (using compression:zip)












0














In eXist 4.4/XQuery 3.1, I am building a function to compress a number of xml files into a zip using compression:zip.



I have one function which collects all the URIs for the documents to be compressed, schedule:get-document-uris-for-zip(xmlid as xs:string). This function returns lists of documents like the following:



/db/apps/deheresi/data/MS609-0001.xml
/db/apps/deheresi/data/MS609-0002.xml
/db/apps/deheresi/data/MS609-0003.xml
/db/apps/deheresi/data/MS609-0004.xml
/db/apps/deheresi/data/MS609-0005.xml
/db/apps/deheresi/data/MS609-0006.xml
/db/apps/deheresi/data/MS609-0007.xml
/db/apps/deheresi/data/MS609-0008.xml
/db/apps/deheresi/data/MS609-0009.xml
/db/apps/deheresi/data/MS609-0010.xml


This function is called by the compression function as follows



declare function schedule:create-zip-by-batch()
{
let $batch := doc(concat($globalvar:URIdocuments,"document_collections.xml"))

for $entry in $batch//collection[@compile="y"]

let $zipobject := compression:zip(schedule:get-document-uris-for-zip($entry/string(@xml:id)),false())

let $zipstore := xmldb:store("/db/apps/deheresi/documents",
"MS609_tei.zip",
$zipobject)

return $zipstore
};


This is throwing a cast error as follows, but I can't identify how to resolve this...



org.exist.xquery.value.StringValue cannot be cast to org.exist.xquery.value.AnyURIValue


Many thanks in advance.



Edit - I'm adding here the part of the function schedule:get-document-uris-for-zip(xmlid as xs:string) which outputs the list of URIs. The URIs are built through string concatenation:



       (: get names of documents which meet criteria :)
let $list := xmldb:get-child-resources("/db/apps/deheresi/data")[starts-with(., $y/string(@filename)) and ends-with(., $y/string(@ext))]

(: create URI for each document :)
return
for $n in $list
return concat("/db/apps/deheresi/data/",$n)









share|improve this question





























    0














    In eXist 4.4/XQuery 3.1, I am building a function to compress a number of xml files into a zip using compression:zip.



    I have one function which collects all the URIs for the documents to be compressed, schedule:get-document-uris-for-zip(xmlid as xs:string). This function returns lists of documents like the following:



    /db/apps/deheresi/data/MS609-0001.xml
    /db/apps/deheresi/data/MS609-0002.xml
    /db/apps/deheresi/data/MS609-0003.xml
    /db/apps/deheresi/data/MS609-0004.xml
    /db/apps/deheresi/data/MS609-0005.xml
    /db/apps/deheresi/data/MS609-0006.xml
    /db/apps/deheresi/data/MS609-0007.xml
    /db/apps/deheresi/data/MS609-0008.xml
    /db/apps/deheresi/data/MS609-0009.xml
    /db/apps/deheresi/data/MS609-0010.xml


    This function is called by the compression function as follows



    declare function schedule:create-zip-by-batch()
    {
    let $batch := doc(concat($globalvar:URIdocuments,"document_collections.xml"))

    for $entry in $batch//collection[@compile="y"]

    let $zipobject := compression:zip(schedule:get-document-uris-for-zip($entry/string(@xml:id)),false())

    let $zipstore := xmldb:store("/db/apps/deheresi/documents",
    "MS609_tei.zip",
    $zipobject)

    return $zipstore
    };


    This is throwing a cast error as follows, but I can't identify how to resolve this...



    org.exist.xquery.value.StringValue cannot be cast to org.exist.xquery.value.AnyURIValue


    Many thanks in advance.



    Edit - I'm adding here the part of the function schedule:get-document-uris-for-zip(xmlid as xs:string) which outputs the list of URIs. The URIs are built through string concatenation:



           (: get names of documents which meet criteria :)
    let $list := xmldb:get-child-resources("/db/apps/deheresi/data")[starts-with(., $y/string(@filename)) and ends-with(., $y/string(@ext))]

    (: create URI for each document :)
    return
    for $n in $list
    return concat("/db/apps/deheresi/data/",$n)









    share|improve this question



























      0












      0








      0







      In eXist 4.4/XQuery 3.1, I am building a function to compress a number of xml files into a zip using compression:zip.



      I have one function which collects all the URIs for the documents to be compressed, schedule:get-document-uris-for-zip(xmlid as xs:string). This function returns lists of documents like the following:



      /db/apps/deheresi/data/MS609-0001.xml
      /db/apps/deheresi/data/MS609-0002.xml
      /db/apps/deheresi/data/MS609-0003.xml
      /db/apps/deheresi/data/MS609-0004.xml
      /db/apps/deheresi/data/MS609-0005.xml
      /db/apps/deheresi/data/MS609-0006.xml
      /db/apps/deheresi/data/MS609-0007.xml
      /db/apps/deheresi/data/MS609-0008.xml
      /db/apps/deheresi/data/MS609-0009.xml
      /db/apps/deheresi/data/MS609-0010.xml


      This function is called by the compression function as follows



      declare function schedule:create-zip-by-batch()
      {
      let $batch := doc(concat($globalvar:URIdocuments,"document_collections.xml"))

      for $entry in $batch//collection[@compile="y"]

      let $zipobject := compression:zip(schedule:get-document-uris-for-zip($entry/string(@xml:id)),false())

      let $zipstore := xmldb:store("/db/apps/deheresi/documents",
      "MS609_tei.zip",
      $zipobject)

      return $zipstore
      };


      This is throwing a cast error as follows, but I can't identify how to resolve this...



      org.exist.xquery.value.StringValue cannot be cast to org.exist.xquery.value.AnyURIValue


      Many thanks in advance.



      Edit - I'm adding here the part of the function schedule:get-document-uris-for-zip(xmlid as xs:string) which outputs the list of URIs. The URIs are built through string concatenation:



             (: get names of documents which meet criteria :)
      let $list := xmldb:get-child-resources("/db/apps/deheresi/data")[starts-with(., $y/string(@filename)) and ends-with(., $y/string(@ext))]

      (: create URI for each document :)
      return
      for $n in $list
      return concat("/db/apps/deheresi/data/",$n)









      share|improve this question















      In eXist 4.4/XQuery 3.1, I am building a function to compress a number of xml files into a zip using compression:zip.



      I have one function which collects all the URIs for the documents to be compressed, schedule:get-document-uris-for-zip(xmlid as xs:string). This function returns lists of documents like the following:



      /db/apps/deheresi/data/MS609-0001.xml
      /db/apps/deheresi/data/MS609-0002.xml
      /db/apps/deheresi/data/MS609-0003.xml
      /db/apps/deheresi/data/MS609-0004.xml
      /db/apps/deheresi/data/MS609-0005.xml
      /db/apps/deheresi/data/MS609-0006.xml
      /db/apps/deheresi/data/MS609-0007.xml
      /db/apps/deheresi/data/MS609-0008.xml
      /db/apps/deheresi/data/MS609-0009.xml
      /db/apps/deheresi/data/MS609-0010.xml


      This function is called by the compression function as follows



      declare function schedule:create-zip-by-batch()
      {
      let $batch := doc(concat($globalvar:URIdocuments,"document_collections.xml"))

      for $entry in $batch//collection[@compile="y"]

      let $zipobject := compression:zip(schedule:get-document-uris-for-zip($entry/string(@xml:id)),false())

      let $zipstore := xmldb:store("/db/apps/deheresi/documents",
      "MS609_tei.zip",
      $zipobject)

      return $zipstore
      };


      This is throwing a cast error as follows, but I can't identify how to resolve this...



      org.exist.xquery.value.StringValue cannot be cast to org.exist.xquery.value.AnyURIValue


      Many thanks in advance.



      Edit - I'm adding here the part of the function schedule:get-document-uris-for-zip(xmlid as xs:string) which outputs the list of URIs. The URIs are built through string concatenation:



             (: get names of documents which meet criteria :)
      let $list := xmldb:get-child-resources("/db/apps/deheresi/data")[starts-with(., $y/string(@filename)) and ends-with(., $y/string(@ext))]

      (: create URI for each document :)
      return
      for $n in $list
      return concat("/db/apps/deheresi/data/",$n)






      exist-db xquery-3.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 13:42







      jbrehr

















      asked Nov 12 '18 at 13:06









      jbrehrjbrehr

      115212




      115212
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You're right to find this function a bit confusing. The (eXist-specific) compression:zip() function $sources parameter is typed as if it is quite flexible way, as xs:anyType()+. But really it is quite strict about the two types of item it accepts: a sequence of URIs (i.e., of type xs:anyURI), or a sequence of <entry> elements:



          <entry name="filename.ext" 
          type="collection|uri|binary|xml|text"
          method="deflate|store"
          >data</entry>


          See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression#zip.2.



          The problem with your code is that you are passing strings in your $sources parameter, and have not cast these strings as xs:anyURI.



          Here is sample working code:



          xquery version "3.1";

          let $prepare :=
          (
          xmldb:create-collection("/db", "test"),
          xmldb:store("/db/test", "test.xml", <test/>)
          )
          let $zip := compression:zip("/db/test/test.xml" cast as xs:anyURI, false())
          return
          xmldb:store("/db/test", "test.zip", $zip)





          share|improve this answer























          • The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
            – jbrehr
            Nov 12 '18 at 14:07










          • Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
            – jbrehr
            Nov 12 '18 at 14:37










          • I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
            – jbrehr
            Nov 12 '18 at 18:33






          • 1




            I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
            – joewiz
            Nov 12 '18 at 23:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262831%2fexist-db-xquery-stringvalue-cannot-be-cast-to-anyurivalue-using-compressionz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You're right to find this function a bit confusing. The (eXist-specific) compression:zip() function $sources parameter is typed as if it is quite flexible way, as xs:anyType()+. But really it is quite strict about the two types of item it accepts: a sequence of URIs (i.e., of type xs:anyURI), or a sequence of <entry> elements:



          <entry name="filename.ext" 
          type="collection|uri|binary|xml|text"
          method="deflate|store"
          >data</entry>


          See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression#zip.2.



          The problem with your code is that you are passing strings in your $sources parameter, and have not cast these strings as xs:anyURI.



          Here is sample working code:



          xquery version "3.1";

          let $prepare :=
          (
          xmldb:create-collection("/db", "test"),
          xmldb:store("/db/test", "test.xml", <test/>)
          )
          let $zip := compression:zip("/db/test/test.xml" cast as xs:anyURI, false())
          return
          xmldb:store("/db/test", "test.zip", $zip)





          share|improve this answer























          • The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
            – jbrehr
            Nov 12 '18 at 14:07










          • Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
            – jbrehr
            Nov 12 '18 at 14:37










          • I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
            – jbrehr
            Nov 12 '18 at 18:33






          • 1




            I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
            – joewiz
            Nov 12 '18 at 23:46
















          1














          You're right to find this function a bit confusing. The (eXist-specific) compression:zip() function $sources parameter is typed as if it is quite flexible way, as xs:anyType()+. But really it is quite strict about the two types of item it accepts: a sequence of URIs (i.e., of type xs:anyURI), or a sequence of <entry> elements:



          <entry name="filename.ext" 
          type="collection|uri|binary|xml|text"
          method="deflate|store"
          >data</entry>


          See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression#zip.2.



          The problem with your code is that you are passing strings in your $sources parameter, and have not cast these strings as xs:anyURI.



          Here is sample working code:



          xquery version "3.1";

          let $prepare :=
          (
          xmldb:create-collection("/db", "test"),
          xmldb:store("/db/test", "test.xml", <test/>)
          )
          let $zip := compression:zip("/db/test/test.xml" cast as xs:anyURI, false())
          return
          xmldb:store("/db/test", "test.zip", $zip)





          share|improve this answer























          • The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
            – jbrehr
            Nov 12 '18 at 14:07










          • Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
            – jbrehr
            Nov 12 '18 at 14:37










          • I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
            – jbrehr
            Nov 12 '18 at 18:33






          • 1




            I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
            – joewiz
            Nov 12 '18 at 23:46














          1












          1








          1






          You're right to find this function a bit confusing. The (eXist-specific) compression:zip() function $sources parameter is typed as if it is quite flexible way, as xs:anyType()+. But really it is quite strict about the two types of item it accepts: a sequence of URIs (i.e., of type xs:anyURI), or a sequence of <entry> elements:



          <entry name="filename.ext" 
          type="collection|uri|binary|xml|text"
          method="deflate|store"
          >data</entry>


          See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression#zip.2.



          The problem with your code is that you are passing strings in your $sources parameter, and have not cast these strings as xs:anyURI.



          Here is sample working code:



          xquery version "3.1";

          let $prepare :=
          (
          xmldb:create-collection("/db", "test"),
          xmldb:store("/db/test", "test.xml", <test/>)
          )
          let $zip := compression:zip("/db/test/test.xml" cast as xs:anyURI, false())
          return
          xmldb:store("/db/test", "test.zip", $zip)





          share|improve this answer














          You're right to find this function a bit confusing. The (eXist-specific) compression:zip() function $sources parameter is typed as if it is quite flexible way, as xs:anyType()+. But really it is quite strict about the two types of item it accepts: a sequence of URIs (i.e., of type xs:anyURI), or a sequence of <entry> elements:



          <entry name="filename.ext" 
          type="collection|uri|binary|xml|text"
          method="deflate|store"
          >data</entry>


          See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/compression#zip.2.



          The problem with your code is that you are passing strings in your $sources parameter, and have not cast these strings as xs:anyURI.



          Here is sample working code:



          xquery version "3.1";

          let $prepare :=
          (
          xmldb:create-collection("/db", "test"),
          xmldb:store("/db/test", "test.xml", <test/>)
          )
          let $zip := compression:zip("/db/test/test.xml" cast as xs:anyURI, false())
          return
          xmldb:store("/db/test", "test.zip", $zip)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 '18 at 23:42

























          answered Nov 12 '18 at 14:04









          joewizjoewiz

          3,7621120




          3,7621120












          • The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
            – jbrehr
            Nov 12 '18 at 14:07










          • Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
            – jbrehr
            Nov 12 '18 at 14:37










          • I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
            – jbrehr
            Nov 12 '18 at 18:33






          • 1




            I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
            – joewiz
            Nov 12 '18 at 23:46


















          • The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
            – jbrehr
            Nov 12 '18 at 14:07










          • Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
            – jbrehr
            Nov 12 '18 at 14:37










          • I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
            – jbrehr
            Nov 12 '18 at 18:33






          • 1




            I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
            – joewiz
            Nov 12 '18 at 23:46
















          The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
          – jbrehr
          Nov 12 '18 at 14:07




          The same documentation says "$sources The sequence of URI's and/or Entrys" I am trying to pass a sequence of URIs instead of having to construct a list of entries.
          – jbrehr
          Nov 12 '18 at 14:07












          Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
          – jbrehr
          Nov 12 '18 at 14:37




          Also, the error reported seems to point to compression:zip() accepting URIs, but not able to accept the xs:string paths as URIs.
          – jbrehr
          Nov 12 '18 at 14:37












          I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
          – jbrehr
          Nov 12 '18 at 18:33




          I managed to trick the function into accepting URIs but the processing took far too long. I switched the process over to entry and it works fine.
          – jbrehr
          Nov 12 '18 at 18:33




          1




          1




          I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
          – joewiz
          Nov 12 '18 at 23:46




          I'd forgotten about the "sequence of URIs" option and overlooked them in my initial answer. I've always used the <entry> approach because I often zip up in-memory items rather than on-disk resources, and when creating epubs, one of the required metadata resources has to be zipped without compression - using method="store". These options aren't possible with the "sequence of URIs", but I can see how nice it is to avoid constructing <entry> elements.
          – joewiz
          Nov 12 '18 at 23:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262831%2fexist-db-xquery-stringvalue-cannot-be-cast-to-anyurivalue-using-compressionz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ