Answer Files Overview
When you assemble a template in HotDocs, you can save the answers you enter in an answer file. This answer file can subsequently be used to recreate the same document or assemble other documents that require the same information. Assembling a template with a particular answer file will always produce the same completed document.
For example, perhaps you are creating several estate planning documents that require much of the same information, like names, addresses, and important dates. You can save your answers in an answer file and then use that answer file when assembling other estate planning documents. This eliminates the need to re-enter information you've already provided.
Answer File Format
HotDocs answer files are saved in an XML format that adheres to the HotDocs Answer File Schema, which describes their structure and content. These answer files normally use a .anx file name extension.
For example, if you have a non-repeating Text variable named Employee First Name, an answer for that variable would have the following structure in the answer file:
<![CDATA[
<Answer name="Employee First Name">
<TextValue>Jonathan</TextValue>
</Answer>
]]>
Where:
- The <Answer>...</Answer> tag pair denotes a new answer in the answer set.
- The name attribute denotes the name of the variable to which the the answer applies. In this case, Employee First Name.
- The <TextValue>...</TextValue> tag pair denotes the answer is for a text variable.
- The text between the TextValue tag pair, Jonathan, is the answer text. When the template is assembled using the answer file, Jonathan is the value that will appear in the Employee First Name answer field.
HotDocs can also supply multiple answer values for a variable, if that variable is a Repeat Variable. Repeat variables appear in a repeating type dialog or within a REPEAT instruction in the template. Each answer for the variable is assigned an index number. When the answers are loaded into the template, the appropriate answer is assigned to each instance of the repeat. For example:
<![CDATA[
<Answer name="Job Title">
<RptValue>
<TextValue>Junior Technician</TextValue>
<TextValue>Lead Technician</TextValue>
</RptValue>
</Answer>
]]>
The Answer tag and name attribute are the same as the previous example. However, the TextValue tag and answer text are now enclosed by a RptValue tag. This is the Repeat tag. Each answer has an index value based on the order in which the answers appear in the template. In this example, the first answer entered into the interview ("Junior Technician") has a repeat index of 1. Every time the answer file is used with the template, the answer Junior Technician will appear in the first repeat of the Job Title answer variable.
For more information on repeat indexing or answer files in general, please see the HotDocs Developer Help File.
Using Answer Files with HotDocs Cloud Services
The ability to save and archive answer files in your host application is critical as it allows End Users to re-use existing information, present and modify this information in interviews, and re-assemble specific documents as needed.
The GetInterview and AssembleDocument methods of the HotDocs Cloud Services web service accept an array of answer files to use with the request. If you do not want to use an existing answer file, you can pass a null value for the answers parameter of those methods.
The POSTed response from an interview contains an encoded set of answers, which you can use with GetInterview or AssembleDocument just like any ordinary XML answer file. If you want to get an XML version of those answers, however, you can call GetAnswers or AssembleDocument and request an answer file as one of the file outputs.
Depending on the requirements of your host application, you may also need to create answer files from scratch.
For example, you could pull information from a database and build an answer file you can then use to assemble a document without even displaying an interview, or you could use those answers to seed the interview with default answers.
When creating this answer file, you can refer to the HotDocs Answer File Schema to ensure that you create an XML file that will be read correctly by HotDocs Cloud Services. The GetComponentInfo method is also useful when creating an answer file because it will give you a list of which variables are used by a particular template; the answer file you create can then supply an answer for each variable in that list for which you can find a suitable answer in your database.
At times, your host application may also need to read answers from an answer file. The XML schema can be useful in understanding the structure of the XML so you can find the answers you need, and the GetComponentInfo method mayalso help you determine which answers in a file are relevant to a particular template.
(Answer files may be used with multiple templates, so an answer file will contain not only common answers used by all templates, but also answers that are specific to individual templates.)
See Get Interview for more information about seeding interviews with answers and handling answers returned from an interview.