Re: [EXTERNAL] json-ignore-whitespace-text-nodes
Joe Wicentowski <[email protected]>
| Newsgroups | gmane.text.xml.exist |
|---|---|
| Message-ID | <CAHwerk2iPnPoKftGYKCEvT2En9NNgu2EWVUinMqcEoyHueSSEA@mail.gmail.com> |
Hi Bernie,
Great, thanks for confirming that and testing with the exist namespace
prefix. I do not know if this serialization parameter is available in the
RESTXQ context.
Looking at the history of the RESTXQ serializer code, it appears that it's
had to be updated whenever new serialization properties have been added to
eXist. This suggests that if your code is not working, that RESTXQ has to
be updated to support this serialization property.
You might look into constructing your JSON with XQuery, instead of relying
on eXist's own XML-to-JSON serialization handling. (For reference, these
are the rules exist applies:
https://exist-db.org/exist/apps/wiki/blogs/eXist/JSONSerializer.)
Or as a real kludge, you could re-parse the serialized JSON:
```
xquery version "3.1";
declare namespace hdp="http://www.spase-group.org/data/schema";
let $node := <hdp:result xmlns="http://www.spase-group.org/data/schema">
<hdp:collection>
<hdp:resource>
<Spase xmlns="http://www.spase-group.org/data/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.spase-group.org/data/schema
https://www.spase-group.org/data/schema/spase-2_4_0.xsd">
<Version>2.4.0</Version>
<NumericalData>
<ResourceID>spase://NASA/NumericalData/ACE/CRIS/L2/PT1H</ResourceID>
<ResourceHeader>
<ResourceName>ACE Cosmic Ray Isotope Spectrometer (CRIS) 1-Hour
Level 2 Data</ResourceName>
<DOI>https://doi.org/10.48322/g72t-0814</DOI>
<ReleaseDate>2022-05-17T12:34:56.789</ReleaseDate>
</ResourceHeader>
</NumericalData>
</Spase></hdp:resource></hdp:collection></hdp:result>
let $serialized := serialize($node, map { "method": "json",
"exist:json-ignore-whitespace-text-nodes": true() })
return
parse-json($serialized)
```
This returns:
```
map {
"collection": map {
"resource": map {
"Spase": map {
"xsi:schemaLocation": "
http://www.spase-group.org/data/schema
https://www.spase-group.org/data/schema/spase-2_4_0.xsd",
"NumericalData": map {
"ResourceID":
"spase://NASA/NumericalData/ACE/CRIS/L2/PT1H",
"ResourceHeader": map {
"DOI": "https://doi.org/10.48322/g72t-0814",
"ResourceName": "ACE Cosmic Ray Isotope
Spectrometer (CRIS) 1-Hour Level 2 Data",
"ReleaseDate": "2022-05-17T12:34:56.789"
}
},
"Version": "2.4.0"
}
}
}
}
```
Returning this in your RESTXQ function should work (though I haven't tested
it).
Joe
On Thu, Jan 26, 2023 at 1:57 PM Harris, Bernard T. (GSFC-5870) <
[email protected]> wrote:
> And I still have the problem with
>
> <exist:json-ignore-whitespace-text-nodes value="yes" />
>
>
>
> Bernie
>
>
>
> *From: *"Harris, Bernard T. (GSFC-5870)" <[email protected]>
> *Date: *Thursday, January 26, 2023 at 1:52 PM
> *To: *Joe Wicentowski <[email protected]>
> *Cc: *Exist-open <[email protected]>
> *Subject: *Re: [Exist-open] [EXTERNAL] json-ignore-whitespace-text-nodes
>
>
>
> I saw it but did not think it was applicable since I was not explicitly
> calling serialize. But just now, I added an extra line to my example
>
>
>
> <rest:response>
>
> <output:serialization-parameters>
>
> <output:method value="json" />
>
> <output:json-ignore-whitespace-text-nodes value="yes" />
>
> </output:serialization-parameters>
>
> <http:response>
>
> <http:header name="Content-Type" value="application/json"
> />
>
> </http:response>
>
> </rest:response>,
>
>
>
> And reran the test. It does not change the output. I still get a bunch
> of “#text” stuff.
>
>
>
> Bernie
>
>
>
> *From: *Joe Wicentowski <[email protected]>
> *Date: *Thursday, January 26, 2023 at 1:42 PM
> *To: *"Harris, Bernard T. (GSFC-5870)" <[email protected]>
> *Cc: *Exist-open <[email protected]>
> *Subject: *Re: [Exist-open] [EXTERNAL] json-ignore-whitespace-text-nodes
>
>
>
> Hi Bernie,
>
>
> Did you by chance see my earlier response with links to code demonstrating
> how to use the json-ignore-whitespace-text-nodes property?
>
>
>
> Joe
>
>
>
> On Thu, Jan 26, 2023 at 1:32 PM Harris, Bernard T. (GSFC-5870) <
> [email protected]> wrote:
>
> https://cdaweb.gsfc.nasa.gov/registry/hdp/restxqJson-0.1.xar
>
> contains an example app that demonstrates my problem. Once the
> application is install,
>
>
>
> $ curl http://localhost:8100/exist/restxq/test
>
> { "collection" : { "resource" : { "Spase" : { "xsi:schemaLocation" : http://www.spase-group.org/data/schema
> https://www.spase-group.org/data/schema/spase-2_4_0.xsd
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.spase-group.org%2Fdata%2Fschema%2520https%3A%2Fwww.spase-group.org%2Fdata%2Fschema%2Fspase-2_4_0.xsd&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=JDLepR8iMWsG2SJ8bXCDAatYqmV9Y8CReHu99XeqE7U%3D&reserved=0>,
> "#text" : ["\n ", "\n ", "\n" ], "Version" : "2.4.0", "NumericalData" :
> { "#text" : ["\n ", "\n ", "\n " ], "ResourceID" :
> "spase://NASA/NumericalData/ACE/CRIS/L2/PT1H", "ResourceHeader" : { "#text"
> : ["\n ", "\n ", "\n ", "\n " ],
> "ResourceName" : "ACE Cosmic Ray Isotope Spectrometer (CRIS) 1-Hour Level 2
> Data", "DOI" : https://doi.org/10.48322/g72t-0814
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.48322%2Fg72t-0814&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=lGrJL%2BI77%2FMd%2F56pG93TJtx%2BxHHUNuFX7sfZMjUQAoA%3D&reserved=0>,
> "ReleaseDate" : "2022-05-17T12:34:56.789" } } } } }
>
>
>
> Demonstrates the problem. If you change the code to
>
> let $example := 2
>
> so that the xml does not come from the db, the json will not contain all
> the “#text” stuff. Let me know if you need anything else. Thanks for
> looking at this.
>
>
>
> Bernie Harris
>
>
>
> *From: *"Harris, Bernard T. (GSFC-5870)" <[email protected]>
> *Date: *Thursday, January 26, 2023 at 5:26 AM
> *To: *Joe Wicentowski <[email protected]>
> *Cc: *Exist-open <[email protected]>
> *Subject: *Re: [Exist-open] [EXTERNAL] json-ignore-whitespace-text-nodes
>
>
>
> I’m still attempting to reproduce in a minimal amount of code but it is
> taking a lot of time. But maybe just seeing the output will be enough for
> you to know what is wrong. This is a RESTXQ application and I first
> noticed the problem on exist 6.0.1 but have also now reproduced it on 4.4.
> Here is a little bit of the output
>
>
>
> $ curl -s -H "Accept: application/json"
> http://localhost:8100/exist/restxq/Spase/NumericalData?ResourceID=spase://NASA/NumericalData/ACE/MAG/L2/PT16S
> |jq |head -15
>
> {
>
> "collection": {
>
> "resource": {
>
> "Spase": {
>
> "xsi:schemaLocation": http://www.spase-group.org/data/schema
> https://www.spase-group.org/data/schema/spase-2_3_2.xsd
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.spase-group.org%2Fdata%2Fschema%2520%2520https%3A%2Fwww.spase-group.org%2Fdata%2Fschema%2Fspase-2_3_2.xsd&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=fIKPZfwfeBYomcQtNKigX4mnl95WBz1z9WhoIKBsU6E%3D&reserved=0>
> ,
>
> "#text": [
>
> "\n ",
>
> "\n ",
>
> "\n"
>
> ],
>
> "Version": "2.3.2",
>
> "NumericalData": {
>
> "#text": [
>
> "\n ",
>
> "\n ",
>
>
>
> The problem is all the extra #text values. They don’t appear in the xml
> output. Years ago when I developed something similar without RESTXQ, this
>
>
>
> declare option exist:serialize "json-ignore-whitespace-text-nodes=yes";
>
>
>
> eliminated the extra #text stuff. But that does not work in my RESTXQ
> app. and it will take me more time to create a minimal RESTXQ example. I
> would apricate any help you can give but understand if you need example
> code.
>
>
>
> Bernie
>
>
>
> *From: *Joe Wicentowski <[email protected]>
> *Date: *Wednesday, January 25, 2023 at 6:07 AM
> *To: *"Harris, Bernard T. (GSFC-5870)" <[email protected]>
> *Cc: *Exist-open <[email protected]>
> *Subject: *Re: [Exist-open] [EXTERNAL] json-ignore-whitespace-text-nodes
>
>
>
> Could you provide more info? How to reproduce? Expected vs. actual
> results? What version of eXist?
>
>
>
> On Wed, Jan 25, 2023 at 5:39 AM Harris, Bernard T. (GSFC-5870) via
> Exist-open <[email protected]> wrote:
>
> I noticed the same thing. But I was working with RESTXQ (and exist-db
> 6.0.1) for the first time and thought I might need to do things differently
> than the way it had worked in the past. I would like to know if this is a
> bug or if there is a different way to accomplish the same thing.
>
>
>
> Bernie Harris
>
>
>
> *From: *Eduard Drenth <[email protected]>
> *Date: *Sunday, January 22, 2023 at 11:22 AM
> *To: *Exist-open <[email protected]>
> *Subject: *[EXTERNAL] [Exist-open] json-ignore-whitespace-text-nodes
>
>
>
> json-ignore-whitespace-text-nodes not supported anymore?
>
>
>
>
>
>
>
> Eduard Drenth, Software Architekt
>
>
>
> [email protected]
>
>
>
> Doelestrjitte 8
>
> 8911 DX Ljouwert
>
> (058) 213 14 14
>
> +31 62 094 34 28
>
> https://www.fryske-akademy.nl/
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.fryske-akademy.nl%2F&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=iKPW3w5hT7zCv%2F3FORRs7AbwmaNL%2F8Ll5EaNkkQIwns%3D&reserved=0>
>
> https://frysker.nl/
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Ffrysker.nl%2F&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=9eMUDr0ES2uRkRPhhe%2FVP33hpglV1%2B8Q10JBfpWss6M%3D&reserved=0>
>
> https://frisian.eu/
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Ffrisian.eu%2F&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=%2B0l%2FnBilBZdzESuGGLthhiE2DERf%2BKAvBwJm3V%2FBZ3U%3D&reserved=0>
>
> gpg: pgp.key-server.io/pks/lookup?search=eduarddrenth
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpgp.key-server.io%2Fpks%2Flookup%3Fsearch%3Deduarddrenth&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=ilxi51ZR4iMEUnOL4MxFWG0jyflw5fmnaGXqq5KYqqA%3D&reserved=0>
>
> _______________________________________________
> Exist-open mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/exist-open
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fexist-open&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7C8eef6bc44fc249de20b008daffccc15d%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638103553796310665%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000%7C%7C%7C&sdata=T4finZMlulTU9YjweRgqGS84auNJj9ehC3SoKcoJtZ4%3D&reserved=0>
>
> --
>
> Sent from my iPhone
>
>
_______________________________________________
Exist-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/exist-open
image001.png
(image/png, 10.6 KB) - not displayed