Menu

How to create new templates

Help
spah
2008-06-11
2012-09-14
  • spah

    spah - 2008-06-11

    Steve, just following up to my email to you .. I had a few questions regarding the FDS package:

    1. Could you possibly tell me how a sample template (XML) looks like?
    2. Also do you have a cheat sheet of the template tags that FDS looks for?

    Thanks,
    SP

     
    • spah

      spah - 2008-06-11

      Steve,

      Thanks for your reply. Yup, I did infact go through the documentation but am missing a couple of pieces:

      1. How does the package know where to put the respective data in the template?

      Basically my need is that I have multiple html forms (100-150+ form fields) and need an XML output of the request paremeters in the XML format below:

      <xml...>

      <fieldname1>fieldvalue1</fieldname1>
      <fieldname2>fieldvalue2</fieldname2>
      <fieldname3>fieldvalue3</fieldname3>
      <fieldname4>fieldvalue4</fieldname4>
      <fieldname5>fieldvalue5</fieldname5>
      and so on ... all dynamically based on the number of input types (which can change).

      Thanks,
      SP

       
      • Steve Souza

        Steve Souza - 2008-06-11

        <<1. How does the package know where to put the respective data in the template? >>
        not sure what you mean by that.

        Look at the xml template in the file and you will see a number of ##variables. For example ##headerThis puts the current header into the data stream as the data iterates. You don't see the data in the template (##this) as displaying data is a default. There may be a base class template defined in the Templates file that always does this. ##this knows which data piece is being iterated and puts in the data stream if it is defined in a template.

        However, try the following and it should look close to what you want.

        String[] header={"field1",...,"field150"};
        Object[][] data={{"value1",....,"value150"}};

        String xml=fds.getFormattedDataSet(header, data, "xml");

        There is an alternative version that takes a rootelement. I forget if that is "xml" or "xml1". You should see both in the Templates link I previously sent you.

         
    • Steve Souza

      Steve Souza - 2008-06-11

      Unfortunately the syntax for templates is not as clean as it should be. But there are plenty of examples.

      The users guide is pretty thorough: http://fdsapi.sourceforge.net/htmldocs/TemplateUsersGuide.htm

      Templates can be created from files, strings or simply by calling methods on the Template API. Also, if you want to use an existing template as your starting point, simpy call Template myTemplate=template.copy();

      The templates class has examples of all out of the box templates. This class uses Strings to generate the templates, but the data could just as easily be put in a file.

      Scroll, down to line 157 and you will see how they are defined. Note how small most of them are.

      http://fdsapi.cvs.sourceforge.net/fdsapi/fdsapi/Code/com/fdsapi/Templates.java?revision=1.8&view=markup

       

Log in to post a comment.

MongoDB Logo MongoDB