freemarker,读取xml格式的数据


有是数据包存在xml文档中

<students>
    <desc>这是关于学生信息的数据</desc>
    <student>
        <name>jack</name>
        <age>12</age>
        <desc>a good boy</desc>
    </student>
    <student>
        <name>jane</name>
        <age>13</age>
        <desc>a beautiful girl</desc>
    </student>
</students>

这是2可以使用 NodeModel.parse("xml文件");来读取数据

@org.junit.Test
    public void TestXmlmodel() throws Exception{
        Configuration cfg=new Configuration(Configuration.VERSION_2_3_25);
        cfg.setClassForTemplateLoading(Test.class, "../../../ftl");
        cfg.setClassForTemplateLoading(FreeMarkerUtil.class, "../../../ftl");
        Template template=cfg.getTemplate("students.ftl");
        Writer out=new OutputStreamWriter(System.out);
        Map map=new HashMap();
        map.put("data", NodeModel.parse(new File("src/xmlmodel/students.xml")));
        template.process(map, out);
    }
test xmlmodel
<#list data.students.student as student>
    ${student.name}
    ${student.age}
    ${student.desc}
</#list>
${data.students.desc}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM