I am creating a data-model from XML content and am trying to use write a template that selects a node (containing child nodes) from the data-model.
final Map<String, NodeModel> root = new HashMap<String, NodeModel>();
root.put("doc", freemarker.ext.dom.NodeModel.parse(new InputSource(new StringReader(response))));
where response is:
<ns:Response xmlns:ns="urn:sdf.sdf.as.v1">
<ns:MessageBody>
<ns:Items>
<ns:Item>
<ns:ItemId>1</ns:ItemId>
</Item>
<ns:Item>
<ns:ItemId>2</ns:ItemId>
</Item>
</ns:Items>
</ns:MessageBody>
</ns:Response>
The template I am trying to come up with is: ${doc.Response.MessageBody.Items}
I get the following exception:
Expecting a string, date or number here, Expression doc.Response.MessageBody.Items is instead a freemarker.ext.dom.NodeListModel
What am I doing wrong? Can Freemarker Template work on an Element node or does it always have to be a node value? Could it be because my template does not contain namespaces? How do I reference namespaces?
No comments:
Post a Comment