06-11-2009 12:14 PM
06-12-2009 04:18 AM
06-12-2009 04:47 AM
public class FreeMarkerXmlParser implements TemplateMethodModel {
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() != 1) {
throw new TemplateModelException("Wrong arguments");
}
return parseXml((String)args.get(0));
}
public NodeModel parseXml(String textData) {
NodeModel docData = null;
try {
docData = freemarker.ext.dom.NodeModel.parse(new InputSource(new StringReader((String) textData)));
} catch (SAXException e) {
} catch (ParserConfigurationException e) {
} catch (IOException e) {}
return docData;
}
}
The application context:
…
<bean abstract="true" id="webscripts.abstractcontainer">
…
<property name="templateObjects">
<map>
<!– method to parse an xml String into Freemarker NodeModel –>
<entry key="parseXml">
<bean class="com.albasoft.alfresco.utils.FreeMarkerXmlParser" />
</entry>
..
Then the template example.
…
<#assign doc = parseXml(response) />
<#list doc.items.item as item>
<tr>
<#list dao.fieldNames as f>
<td>${item[f]!""}</td>
</#list>
</tr>
</#list>
…
where response is an xml String (like):
<items>
<item>
<id></id>
<name></name>
<phone></phone>
</item>
<item>…
</items>
06-12-2009 05:09 AM
Yes, there is an XML parser to read each XML elements and attributes values, you can see more details here:
http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook#XML_Document_Example
<#assign doc = parseXml(args['myDoc']) />
06-12-2009 05:18 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.