Skip to main content
Question

Might there be a bug in the XQuery function fme:process-features (JSONTemplater)

  • February 16, 2017
  • 5 replies
  • 63 views

Forum|alt.badge.img

Hi !

 

 

When using the JSON Templater, loading sub-templates using the xquery fme:process-features, I get an error when one of my json documents (generated by a previous JSON Templater) contains an ampersand (&) 

Here is the error :

JSONTemplater_Annonce(XMLTemplaterFactory): invalid expression: syntax error, invalid character or entity reference "& ASSO..." in the string literal "CABINET PIERRE SMITH & ASSOCIES".

Could it consider the ampersand to be a reserved character of the xquery language even whitin double-quotes ?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

david_r
Celebrity
  • February 16, 2017

Maybe someone else can confirm, but I suspect that the ampersand is considered a special character in XQuery, cf. https://en.wikibooks.org/wiki/XQuery/Special_Characters

Try using a StringReplacer to replace the ampersands with either "&" or to "&".


takashi
Celebrity
  • February 16, 2017

Yes, in XQuery expressions, the ampersand can only be represented using the entity reference or character reference. See also this link.

W3C Recommendation | XQuery 3.0: An XML Query Language | 2.4.5 URI Literals

This expression causes the error.

{
    "CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}

To avoid the error,

a) escape the ampersand with the predefined entity reference (&),

{
    "CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}

b) or save the string literal as a feature attribute (e.g. called "name") beforehand and use FME predefined XQuery function "fme:get-attribute" to put the value in the expression.

{
    fme:get-attribute("name"): "foo bar"
}

Note: Since the function escapes the ampersand internally when the expression is evaluated, you don't need to replace the ampersand within the "name" attribute value with the entity reference.


Forum|alt.badge.img
  • Author
  • February 17, 2017

Yes, in XQuery expressions, the ampersand can only be represented using the entity reference or character reference. See also this link.

W3C Recommendation | XQuery 3.0: An XML Query Language | 2.4.5 URI Literals

This expression causes the error.

{
    "CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}

To avoid the error,

a) escape the ampersand with the predefined entity reference (&),

{
    "CABINET PIERRE SMITH & ASSOCIES": "foo bar"
}

b) or save the string literal as a feature attribute (e.g. called "name") beforehand and use FME predefined XQuery function "fme:get-attribute" to put the value in the expression.

{
    fme:get-attribute("name"): "foo bar"
}

Note: Since the function escapes the ampersand internally when the expression is evaluated, you don't need to replace the ampersand within the "name" attribute value with the entity reference.

Ok ! Thanks for the answer ! If I use "&" do I need to replace it back when loading it (I will use a python caller, load the json in a python dictionnary, then write it in mongodb) ?

 

 

What's bother me though, is that I indeed used fme:get-attribute to create the json structure in a previous JSON Templater, then used the resulting json attribute in the second JSON Templater as a sub-template... (I guess that's why the & is no-longer escaped, the nested json might be passed as a raw string somewhere inbetween)  maybe if I define all the nested sub-templates in the same json templater, the & would be correctly escaped... I will try that.

 


takashi
Celebrity
  • February 17, 2017
Ok ! Thanks for the answer ! If I use "&" do I need to replace it back when loading it (I will use a python caller, load the json in a python dictionnary, then write it in mongodb) ?

 

 

What's bother me though, is that I indeed used fme:get-attribute to create the json structure in a previous JSON Templater, then used the resulting json attribute in the second JSON Templater as a sub-template... (I guess that's why the & is no-longer escaped, the nested json might be passed as a raw string somewhere inbetween) maybe if I define all the nested sub-templates in the same json templater, the & would be correctly escaped... I will try that.

 

I don't think the error could occur even if you are using multiple JSONTemplaters in a series, unless an ampersand exists within a string literal in a template expression. Can you post a workspace example which illustrates your problem?

 


Forum|alt.badge.img
  • Author
  • February 21, 2017
I don't think the error could occur even if you are using multiple JSONTemplaters in a series, unless an ampersand exists within a string literal in a template expression. Can you post a workspace example which illustrates your problem?

 

Yes ! I will try to create a specific workspace to showcase this