cancel
Showing results for 
Search instead for 
Did you mean: 

Adding namespaces to .ftl

shmoula
Champ in-the-making
Champ in-the-making
Hi!
  Im trying to process a XML document like

<a:blabla>
  <b:blabla>
    <c:somestuff>xxx</c:somestuff>
  </b:blabla>
</a:blabla>
via freemarker template, which offering entering namespaces like

<#ftl ns_prefixes={
"a", "http://www.something.org/somewhere",
"b","http://something.else/somewhere/"
}
but i cant pass this notation through "alfresco version" of FreeMarker. Can someone please help me, how can i manipulate with that document? Thanks a lot!
8 REPLIES 8

mikeh
Star Contributor
Star Contributor
Hi

Have you got the correct syntax? I thought the ftl directive should be more like:
<#ftl ns_prefixes={
"a":"http://www.something.org/somewhere",
"b":"http://something.else/somewhere/"
}>

shmoula
Champ in-the-making
Champ in-the-making
thanks for response!
yes, i use the right form, i think, i made mistake just by entering information to forum, my copy&paste:

<#ftl ns_prefixes={"are":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3",
"D":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_datatypes/v_1.0.3",
"U":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/uvis_datatypes/v_1.0.3"}>
and on "tomcat console"

…Caused by: freemaker.core.ParseException: Encountered "<#ftl " at line 2…
Was expecting one of:
<ATTEMPT>…

mikeh
Star Contributor
Star Contributor
Two things possibly causing this…

1. The <#ftl ..> has to be the very first line of the template (your error is occurring on Line 2)

2. The "D" namespace is reserved by Freemarker (as is the "N" prefix) unless you're sure you know you want to override it.


Thanks,
Mike

shmoula
Champ in-the-making
Champ in-the-making
Oh, many thanks, that is the problem, i think!!! 😉

And one more question…is there any tutorial, or example? I really dont know how to access my structure. I followed http://www.freemarker.org/docs/xgui_imperative_learn.html and http://wiki.alfresco.com/wiki/Template_Guide but my notation still not work.

<?xml version="1.0" ?>
<are:Ares_odpovedi xmlns:are="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3" Id="Ares_odpoved">
  <are:Odpoved>
      somestuff
    <bbb:Odpoved2>
      someotherstuff
    </bbb:Odpoved2>
  </are:Odpoved>
</are:Ares_odpovedi>
and something like


<#list document.childrenByXPath[".//*[subtypeOf('are:Ares_odpovedi')]"] as odpovedi>
      ${odpovedi.content["are:Odpoved"]}
  </#list>

or


<#assign dom=document.xmlNodeModel />
      <#list dom.content["are:Ares_odpovedi"] as cosi>
        <h1>${cosi.content["are:Odpoved"]}</h1>
      </#list>

(and what about <bbbSmiley Surpriseddpoved2>?)

Thanks in advance!

mikeh
Star Contributor
Star Contributor

shmoula
Champ in-the-making
Champ in-the-making
Thanks for fast response again, but those routines i tried, but without result too, or is there any other error in my notation?

<?xml version="1.0" ?>
<are:Ares_odpovedi xmlns:are="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3">
  <are:Odpoved>
      some_plain_text_stuff
  </are:Odpoved>
</are:Ares_odpovedi>

<#ftl ns_prefixes={"are":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3"}>

${.vars["are:Ares_odpovedi/are:Odpoved"]}

Error during processing of the template 'Expression .vars["are:Ares_odpovedi/are:Odpoved"] is undefined on line 3, column 3 in workspace://SpacesStore/1abe32d0-71af-11dc-9d7c-4531dcb10a32.'. Please contact your system administrator.

mikeh
Star Contributor
Star Contributor
I'm not sure why the .vars syntax isn't working, but you should also be able to do something like:
${Ares_odpovedi.Odpoved}


Mike

shmoula
Champ in-the-making
Champ in-the-making
Thanks, but this syntax doesnt work too :-(.

<#ftl ns_prefixes={"are":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3"}>
${Ares_odpovedi.Odpoved}
generates (even thought its defined a line above)

Error during processing of the template 'Expression Ares_odpovedi is undefined on line 2, column 3 in workspace://SpacesStore/1abe32d0-71af-11dc-9d7c-4531dcb10a32.'. Please contact your system administrator.
Nor this one
<#ftl ns_prefixes={"are":"http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_or/v_1.0.3"}>
<#assign Ares_odpovedi = .vars["are:Ares_odpovedi"]>
generates
Error during processing of the template 'Error on line 3, column 1 in workspace://SpacesStore/1abe32d0-71af-11dc-9d7c-4531dcb10a32 .vars["are:Ares_odpovedi"] is undefined. It cannot be assigned to Ares_odpovedi'. Please contact your system administrator.