Quantcast

RestXQ

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RestXQ

Pietro Liuzzo-2
Dear all,

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them using xqjson because @ is not allowed.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:bm:{id}) and this I am not able to find out how to do unfortunately...


thanks for any support!

all best

Pietro

--
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: +49 40 42838-8381


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Fwd: RestXQ

Pietro Liuzzo

Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...

<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
               
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" : "urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" : { "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
   
"@context": {
       
"dts": "http://example.org/dts-ontology/",
       
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
       
"saws" : "http://purl.org/saws/ontology",
       
"tei": "http://www.tei-c.org/ns/1.0"
   
},
   
"@graph": {
       
"@id": "urn:dts:betmas:LIT1113Anqasa",
       
"rdf:type": "work",
       
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
       
"dt:size": "1",
       
"@labels": {
           
"@lang": [
               
"en",
               
"ar",
               
"it",
               
"gez"
           
],
           
"@value": "ʾAnqaṣa bǝrhān",
           
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
       
},
       
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
   
}
}


thanks for any support on this!

all best

Pietro

--
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" target="_blank">+49 40 42838-8381




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Alister Pillow-3
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" target="_blank" class="">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Alister Pillow-3
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" target="_blank" class="">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Pietro Liuzzo
Thanks a lot,

I tested with curl as in your message. I am not sure how to change XQuery 3.0 to 3.1 but I will find out.
thanks a lot!
Pietro 

2017-03-20 8:15 GMT+01:00 Alister Pillow <[hidden email]>:
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" target="_blank">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Alister Pillow-3
xquery version “3.1”;

On 20 Mar 2017, at 6:02 pm, Pietro Liuzzo <[hidden email]> wrote:

Thanks a lot,

I tested with curl as in your message. I am not sure how to change XQuery 3.0 to 3.1 but I will find out.
thanks a lot!
Pietro 

2017-03-20 8:15 GMT+01:00 Alister Pillow <[hidden email]>:
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" target="_blank" class="">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Joe Wicentowski
In reply to this post by Alister Pillow-3
Hi Alister,

Actually, eXide's new default output mode, Adaptive, will display maps and all types of XDM items (arrays, functions, attributes, etc.).  Also the JSON output mode will display plain old JSON.

Joe

On Mon, Mar 20, 2017 at 3:17 AM Alister Pillow <[hidden email]> wrote:
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" class="gmail_msg" target="_blank">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
--
Sent from my iPhone

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Alister Pillow-3
Thanks Joe, so it does - and rather nicely. All the more reason for Pietro to upgrade.
(And I was probably wrong about being able to use xquery 3.1 in eXist 2.2)

On 20 Mar 2017, at 10:21 pm, Joe Wicentowski <[hidden email]> wrote:

Hi Alister,

Actually, eXide's new default output mode, Adaptive, will display maps and all types of XDM items (arrays, functions, attributes, etc.).  Also the JSON output mode will display plain old JSON.

Joe

On Mon, Mar 20, 2017 at 3:17 AM Alister Pillow <[hidden email]> wrote:
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" class="gmail_msg" target="_blank">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
--
Sent from my iPhone


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestXQ

Joe Wicentowski
Ah, sorry!  Yes, the version of eXide in question does require eXist 3.x.  eXist 2.2 supported maps from XQuery 3.1 but not arrays, and the still-not-final spec for XQuery 3.1 changed several functions and added various operators that were not available when eXist 2.2 was released.  eXist 2.2 probably could offer limited support for eXide's adaptive output.  But it wouldn't be a straightforward back port given the various changes mentioned above.  All in all, eXist 3.1.0's support for XQuery 3.1 - the best yet in any version of eXist - is rightly a lure to upgrade from 2.x.

On Mon, Mar 20, 2017 at 8:26 PM Alister Pillow <[hidden email]> wrote:
Thanks Joe, so it does - and rather nicely. All the more reason for Pietro to upgrade.
(And I was probably wrong about being able to use xquery 3.1 in eXist 2.2)

On 20 Mar 2017, at 10:21 pm, Joe Wicentowski <[hidden email]> wrote:

Hi Alister,

Actually, eXide's new default output mode, Adaptive, will display maps and all types of XDM items (arrays, functions, attributes, etc.).  Also the JSON output mode will display plain old JSON.

Joe

On Mon, Mar 20, 2017 at 3:17 AM Alister Pillow <[hidden email]> wrote:
Where are you testing? Are you using eXide? 
Regardless of how you’re running it, you’ll need XQuery version 3.1. (as per my source file below).

A driving force behind the introduction of the map in XQuery was the need to use JSON. 

eXide won’t display a map - which is why I used “curl” - but you can also use Firefox and View Source.
When I run this, the result is pretty-printed (because of the “output:indent” setting) - which is what you requested.



On 20 Mar 2017, at 5:01 pm, Pietro Liuzzo <[hidden email]> wrote:

Dear Alister, 
Thanks a lot,

I have tried your suggestion, but I am not able to get it to work. I had to change XQuery to 3.0 and remove the lang array which was reporting an error but I still  get
Error while serializing xml: java.util.EmptyStackException
thanks a lot!
Pietro

2017-03-20 0:49 GMT+01:00 Alister Pillow <[hidden email]>:
Hi Pietro,

Have you tried constructing the desired JSON as a map{}? 

(: /db/test/json-test.xql :)

xquery version "3.1";
declare option output:method "json";
declare option output:indent "yes";

map {
    "@context": map {
        "dts": "http://example.org/dts-ontology/",
        "saws" : "http://purl.org/saws/ontology",
        "tei": "http://www.tei-c.org/ns/1.0"
    },
    "@graph": map {
        "@id": "urn:dts:betmas:LIT1113Anqasa",
        "rdf:type": "work",
        "dt:size": "1",
        "@labels": map {
            "@lang": [
                "en",
                "ar",
                "it",
                "gez"
            ],
            "@value": "ʾAnqaṣa bǝrhān",
            "description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        },
        "dts:metadata": map {"saws:isAttributedToAuthor": "Yāred"}
    }
}

——
RESULT using curl:

{
  "@graph" : {
    "rdf:type" : "work",
    "dts:metadata" : {
      "saws:isAttributedToAuthor" : "Yāred"
    },
    "dt:size" : "1",
    "@id" : "urn:dts:betmas:LIT1113Anqasa",
    "@labels" : {
      "@lang" : [ "en", "ar", "it", "gez" ],
      "@value" : "ʾAnqaṣa bǝrhān",
      "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \\n            Blessed Virgin.\\n            It is part of the Ethiopic psalter, copied following the . \\n            Tradition ascribes its composition to St. Yāred."
    }
  },
  "@context" : {
  }
}


Regards,
Alister

On 15 Mar 2017, at 6:35 pm, Pietro Liuzzo <[hidden email]> wrote:


Dear all,

I don't think my post from yesterday made it to the list. Apologies if it did and you get this twice, I am adding more details and corrections as well.

I am facing a few issues with restxq in exist 2.2.

I need to output JSON where keys might be @id, @lang, but I find no way to add them, also using xqjson.

Also, I have some values I need to output with namespaces, but declaring them as required in the xquery results in the namespace being omitted in the output. I tried declare copy-namespaces preserve to no avail.

Thirdly I would need the path to include a urn which uses columns (urn:dts:betmas:{id}) and this I am not able to find out how to do unfortunately...

I would also like to make into a pretty printed json, but I gathered in forums this is not yet supported, or am I wrong?

the function (shortened) looks like this

declare namespace saws = "http://purl.org/saws/ontology";

declare
%rest:GET
%rest:path("/BetMas/api/dts/collections/{$id}")
%output:method("json")
function api:dtsCollectionsID($id as xs:string*) {
     return
        <rest:response>...

        </rest:response>,
    <json:value>
        <context>...</context>

<graph>...


<metadata>
                {
element saws:isAttributedToAuthor{//path to the author}}
                
</metadata>

</graph>

  };


but I would like the path to be 


What I can get now has json output (shortned example) is like this

{ "context" : { "dts": "http://example.org/dts-ontology/""rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "saws" : "http://purl.org/saws/ontology""tei": "http://www.tei-c.org/ns/1.0"}, "graph" : { "id" :"urn:dts:betmas:LIT1113Anqasa", "type" : "work", "license" : "http://creativecommons.org/licenses/by-sa/4.0/", "size" : "1", "labels" : { "lang" : ["en", "ar", "it", "gez"], "value" : "ʾAnqaṣa bǝrhān", "description" : "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred." }, "metadata" :{ "isAttributedToAuthor" : "Yāred" } } }


but I would like to get something like this

{
    
"@context": {
        
"dts": "http://example.org/dts-ontology/",
        
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 
        
"saws" : "http://purl.org/saws/ontology",
        
"tei": "http://www.tei-c.org/ns/1.0"
    
},
    
"@graph": {
        
"@id": "urn:dts:betmas:LIT1113Anqasa",
        
"rdf:type": "work",
        
"license": "http://creativecommons.org/licenses/by-sa/4.0/",
        
"dt:size": "1",
        
"@labels": {
            
"@lang": [
                
"en",
                
"ar",
                
"it",
                
"gez"
            
],
            
"@value": "ʾAnqaṣa bǝrhān",
            
"description": "The ʾAnqaṣa bǝrhān is a collection of hymns to be chanted on Sundays in praise of the \n            Blessed Virgin.\n            It is part of the Ethiopic psalter, copied following the . \n            Tradition ascribes its composition to St. Yāred."
        
},
        
"dts:metadata": {"saws:isAttributedToAuthor": "Yāred"}
    
}
}


thanks for any support on this!

all best

Pietro

-- 
Hiob Ludolf Centre for Ethiopian Studies
Room: 136
Alsterterrasse 1
20354 Hamburg
Tel: <a href="tel:040%20428388381" value="+4940428388381" class="gmail_msg" target="_blank">+49 40 42838-8381




-- 
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




--
Pietro Maria Liuzzo
cel (DE): +49 (0) 176 61 000 606
Skype: pietro.liuzzo (Quingentole)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
--
Sent from my iPhone

--
Sent from my iPhone

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Loading...