Validating a HotDocs Answer Set

Some HotDocs Advance API methods may require you to send a HotDocs Answer Set with the request. Answer sets are XML strings that represent the data collected from an interview. The answer set must be validated against the HotDocs Answer Set schema before the request is sent.

Overview

HotDocs answer sets are XML strings that represent the data collected from an interview. You will typically work with answer sets when you create work items using the API. Work items in Advance essentially represent an association between a specific template and an answer set.

In combination, Advance uses the template and answer set to:

  • Populate the fields in the HotDocs interview with answer data
  • Assemble a document – HotDocs uses the answer set data to determine the content in the assembled document

When you create a work item using the API, you can optionally send an answer set with the request, to pre-populate the interview with answers before it is accessed by a user. The answer XML you send with your request must conform to the HotDocs Answer Set schema. This is why the answer set you send must first be validated against the schema.

Common Tasks

Download the HotDocs Answer Set Schemas

The answer XML must conform to the HotDocs answer set schema. The Author and Developer desktop products have separate answer set schemas. You can download the schemas from the following links:

The schemas are also available through the API reference documentation.

Code example (C#)

The following code example demonstrates how to read the answer set schema file (.xsd), read the answer set from a HotDocs answer file (.anx), and validate the answer set against the schema.

public bool IsAnswerXmlValid() { 
  // Answer set schema against which to validate answer XML 
  var schema = File.ReadAllText(@"C:\temp\AuthorAnswerSet.xsd");
 
  // The Answer XML you want to validate 
  var answerXml = File.ReadAllText(@"C:\temp\answerFile.anx"); 
  var answerXmlDocument = XDocument.Parse(answerXml); 
  
  // Create schema set 
  XmlSchemaSet schemaSet = new XmlSchemaSet(); 
  schemaSet.Add(null, XmlReader.Create(new StringReader(schema)));
 
  // Validate answer XML against the schema 
  var valid = true; 
  answerXmlDocument.Validate(schemaSet,(sender, e) => { 
        valid = false; 
 },true); 
 
  return valid; 
}