java - Freemarker: How to put XML into data-model? -


followed freemarker documentation

controller

public modelandview home() {         modelandview mav = new modelandview();         mav.addobject("users", userlist);         mav.addobject("user", "big joe");         mav.addobject("title", "testing initial page, using freemarker!");         try {             mav.addobject("doc", freemarker.ext.dom.nodemodel.parse (new file("c:\\users\\himanshuy\\desktop\\2.xml")));          } catch (saxexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         } catch (parserconfigurationexception e) {             e.printstacktrace();         }         return mav;     } 

error

freemarker template error: "${...}" content: expected string or automatically convertible string (number, date or boolean), evaluated sequence+hash (wrapper: f.e.dom.nodelistmodel): ==> header [in template "index.ftl" @ line 13, column 3 

ftl

<#assign header=doc.title > ${header} 

xml

<book>   <title>test book</title>   <chapter>     <title>ch1</title>     <para>p1.1</para>     <para>p1.2</para>     <para>p1.3</para>   </chapter>   <chapter>     <title>ch2</title>     <para>p2.1</para>     <para>p2.2</para>   </chapter> </book>   

what wrong approach?

that should doc.book.title (and don't need #assign of course), since doc xml document, not same topmost element.


Comments