AnsweredAssumed Answered

Freemarker + Namespace question

Question asked by maephisto on Aug 14, 2007
Hi to everybody.

What is the name of the data model when i create a file using a template against a xml content file? I mean: how can i use multiple namespaces and freemarker to render the result of a web form?

If you have not understood my question please keep reading.

I've a problem with freemarker templates using namespaces in xml content file. When I use different namespaces in xml content file, I am not able to create a template file that could handle all the namespaces: in the press-release.xsd sample in WCM Community 2.0 archive there is the following namespace

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:pr="http://www.alfresco.org/alfresco/pr"
           targetNamespace="http://www.alfresco.org/alfresco/pr"
           elementFormDefault="qualified">
This means that the xml content file will have all elements like <pr:title>, <pr:press_release> and so on. In ftl template there the following instruction

<#ftl ns_prefixes={"D", "http://www.alfresco.org/alfresco/pr"}>
This is a Freemarker directive, that specifies the DEFAULT namespace, so in the template i could write ${press_release.title}, without worrying about the namespace. But what if I have more namespaces? In Freemarker documentation there's a paragraph about XML Namespaces (you can find it here): they say you can use the ns_prefixes directive for ALL the namespaces you want, like the following

<#ftl ns_prefixes={
    "e":"http://example.com/ebook",
    "f":"http://example.com/form",
    "vg":"http://example.com/vectorGraphics"}
>
but in your template you have to write something like ${doc["e:book"]["e:name"]} to retrieve the name of a book. The word "doc" here is the name of the data model which the template is executed against.

Now my question: what is the name of the data model when i create a file using a template against a xml content file? I mean: how can i use multiple namespaces and freemarker to render the result of a web form?

Thx in advance.

Outcomes