Skip to main content
Solved

XMLTemplater: "<>" brackets from strings are converted to html encodings in output

  • Jan 13, 2022 12:52 PM UTC
  • 6 replies
  • 441 views

jasperwis
Enthusiast
Forum|alt.badge.img+19

Hi, I am using a PythonCaller to create an XML string. When I send this string through an XMLTemplater, all "<>" brackets are converted to "&lt;" and "&gt;" (html encodings). Adding a StringReplacer/StringPairReplacer to replace all brackets works fine but can take some time for larger content . Is there a way to prevent the XMLTemplater from converting brackets to encoded brackets?

 

String valuebecomes:

Result_XMLTemplater

Best answer by takashi

Hi @Jasper Wisbecq​ , in this case, this template (XQuery) expression would work.

<Asset>{
    for $x in tokenize(fme:get-attribute("output"),'\s')
    return parse-xml($x)
}</Asset>

 

View original
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.

6 replies

ebygomm
Evangelist
Forum|alt.badge.img+54
  • Evangelist
  • Jan 13, 2022 3:15 PM UTC

If you want to insert an xml fragment into the xml template you need to use {fme:get-xml-attribute("xml")}. For this to work however, it needs to be a valid xml fragment which your example is not


jasperwis
Enthusiast
Forum|alt.badge.img+19
  • Author
  • Enthusiast
  • Jan 13, 2022 3:21 PM UTC

Thanks


takashi
Celebrity
  • Best Answer
  • Jan 13, 2022 3:37 PM UTC

Hi @Jasper Wisbecq​ , in this case, this template (XQuery) expression would work.

<Asset>{
    for $x in tokenize(fme:get-attribute("output"),'\s')
    return parse-xml($x)
}</Asset>

 


ebygomm
Evangelist
Forum|alt.badge.img+54
  • Evangelist
  • Jan 13, 2022 3:47 PM UTC

Hi @Jasper Wisbecq​ , in this case, this template (XQuery) expression would work.

<Asset>{
    for $x in tokenize(fme:get-attribute("output"),'\s')
    return parse-xml($x)
}</Asset>

 

These are the sort of examples that all need to be gathered up and put in the helpfiles as I mentioned @Dale Lutz​ 


jasperwis
Enthusiast
Forum|alt.badge.img+19
  • Author
  • Enthusiast
  • Jan 13, 2022 6:53 PM UTC

If you want to insert an xml fragment into the xml template you need to use {fme:get-xml-attribute("xml")}. For this to work however, it needs to be a valid xml fragment which your example is not

If I add a root node to the fragment, the get-xml-attribute works perfectly indeed. However, for my particular case, the root node is undesired, and I would need a StringReplacer to remove it again after the XMLTemplater. Though this would already be much faster than having to replace all brackets, the solution of @Takashi Iijima​ suits even better


jasperwis
Enthusiast
Forum|alt.badge.img+19
  • Author
  • Enthusiast
  • Jan 13, 2022 6:53 PM UTC

Hi @Jasper Wisbecq​ , in this case, this template (XQuery) expression would work.

<Asset>{
    for $x in tokenize(fme:get-attribute("output"),'\s')
    return parse-xml($x)
}</Asset>

 

Great, thank you Takashi