Search code examples
apidocumentdocumentation-generation

Is there any existing service in HotDocs tools to receive data from an external source to prepare a document?


HotDocs is a tool to generate documents and basically it carries 2 things. First is temple and second is answer file. Template carries variables and data to those variables are pushed through answer file.

Generally answer file is page where is it asks for data and further it generates a document.

Now our requirement is - instead of passing variable's values through answer file, I need to send through a API built using PHP which provides data in JSON format.

IS there any exiting service in HotDocs to serve this kind requests?. I can change the data from JSON to XML if required.


Solution

  • At the moment there is no off the shelf converter from JSON to HotDocs Answer XML however, at HotDocs we do this all the time. If you produce either JSON or XML from your application the data will need to be transformed into the HotDocs answer XML format - e.g.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <AnswerSet title="Demo Answers" version="1.1">
        <Answer name="Employee Name">
            <TextValue>Graham Penman</TextValue>
        </Answer>
        <Answer name="Job Duty">
            <RptValue>
                <TextValue>make tea</TextValue>
                <TextValue>make coffee</TextValue>
                <TextValue>make some cake</TextValue>
            </RptValue>
        </Answer>
        <Answer name="Annual Salary">
            <NumValue>12.0000000</NumValue>
        </Answer>
        <Answer name="Contract Date">
            <DateValue>10/10/2016</DateValue>
        </Answer>
        <Answer name="Paid Seminar Days">
            <TFValue>false</TFValue>
        </Answer>
    </AnswerSet>
    

    There are three key things you need to know to create the answer XML: The data type of your data, the data type in HotDocs and whether the data you are passing is a list or single item.

    So to build the answer XML is relatively easy.

    The answer XML is essentially key value pairs being contained between the opening and closing tags:

     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <AnswerSet title="Demo Answers" version="1.1">
     ...Answers go here
     </AnswerSet>
    

    We then add answers in by adding the following and specifying the variable in the template the answer corresponds to, the actual value (from your data) you want to set the answer to and also the type of data it is in the template - in the example below it is text however, the type in HotDocs are: TextValue (string), NumValue (decimal), TFValue (boolean), DateValue (DateTime) and MCValue (see later on in this answer).

    <Answer name="[Variable name in template]">
         <TextValue>[Value from your data]</TextValue>
    </Answer>
    

    For multiple choices specifically you can select one or more answers so the answer XML format is slightly different:

    <Answer name="[Variable name in template]">
         <MCValue>
              <SelValue>[First selected value]</SelValue>
              <SelValue>[Second selected value]</SelValue>
         </MCValue>
    </Answer>
    

    If you have repeated data you want to put into the document you can use the list repeat format:

    <Answer name="[Variable name in template]">
        <RptValue>
            <[Variable Type]>[First value]</[Variable Type]>
            <[Variable Type]>[Second value]</[Variable Type]>
        </RptValue>
    </Answer>
    

    Once you build this XML structure you can pass this into the assemble document method on the REST services as a string with the template to assemble the corresponding documents.