mustache.java pass xml string

128 views
Skip to first unread message

Anshul Jain

unread,
Jan 16, 2019, 11:10:56 PM1/16/19
to mustache.java
Hi team, 

I am new to the mustache and working around templating part for the JSON/XML format, I am able to work the JSON formatted string into mustache via the mustache factory and template. 

How i can achieve this same thing with XML format is there any in-build support is provided which directly accept the XML and convert the things via template to the desired output ?

<response>
    <result>
        <invoice>
            <status>2</status>
            <deposit_percentage />
            <create_date>2016-09-09</create_date>
            <outstanding>
                <amount>800.00</amount>
                <code>USD</code>
            </outstanding>
        </invoice>
    <result>
<response>



MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("template.mustache");
mustache
.execute(new PrintWriter(System.out), object).flush();

so in place of object what kind of input i have to provide. I have searched across the multiple sites and documentation but no luck.

Can some one help me with this please.

Thanks!

Sam

unread,
Jan 17, 2019, 8:34:36 PM1/17/19
to mustache.java
Hmm. XML doesn't map super cleanly to an object model and that makes this a little difficult in general. Your specific example might be easier. I would probably parse the XML and then generate a nested map. Here is an example where I parse your XML and use it to populate values in a template:

Reply all
Reply to author
Forward
0 new messages