Creating a document hierarchy with Datacap object APIs

You can use the Datacap object APIs to create a document hierarchy. For example, you can use these APIs to read a setup DCO XML file and add child objects, including documents, pages, and fields.

Before you begin

This task also assumes that you successfully exported a batch of documents from a database to an XML file.

About this task

Because the use of Datacap object APIs is limited to runtime batches and document hierarchies, the task does not include steps for data recognition and initial calculation of confidence levels.

Procedure

To create a document hierarchy by using Datacap object APIs, complete the following steps:

  1. Use the ReadSetup method read a document hierarchy that you exported:
    m_oDCO.ReadSetup("C:\\temp_location\\exported_application.XML");
  2. Use the WriteSetup method to populate your new setup object and save the document hierarchy as an XML file:
    m_oDCO.WriteSetup("C:\\Datacap\\NEW\\dco_NEW\\NEW.XML")
  3. Optional: Use the AddNode method to add child objects (documents, pages, or fields) to the setup object.

    TheAddNode method uses two arguments: nType lpszNodeName. The nType value (1) specifies that the new node is a document object. The lpszNodeName value specifies that the document object name is NewNode, as shown in the following example:

    m_oDCOSetup.AddNode(1, "NewNode");
    The resulting node in the DCO Setup XML file is <D type="NewNode">.
    Tip: You can similarly add pages, fields, or characters by setting the nType value to 2 (for pages), 3 (for fields), or 4 (for characters).
  4. Use the AddRule method to specify the structure of a document. This step gets the SetupNode object for the NewNode document in the Setup DCO. The step then adds a rule that requires one instance of the page NewPage to exist for the document structure to be valid. If a page node for NewPage does not exist, the method creates NewPage automatically.
    TDCOLib.DCOSetup m_oDCOSetup = m_oDCO.SetupObject();
    TDCOLib.DCOSetupNode m_oDCOSetupNode = 
       m_oDCOSetup.GetNodeByName(1, "NewNode");
    m_oDCOSetupNode.AddRule(2, "NewPage", 0, 1, 1);

    After the execution of the code, the following line is added to the Setup DCO beneath the NewNode document type.

    	<D type="NewNode">
    	.
    	.
    	.
    	<P type="NewPage" pos="0" min="1" max="1"/> <!-- New line added -->

    Additionally, if NewPage does not exist, the following page node is created in the Setup DCO:

    <P type="NewPage">
    	<V n="ID">0</V>
    	<V n="TYPE">Page</V>
    	<V n="STATUS">0</V>
    	<V n="IMAGEFILE"></V>
    	<V n="DATAFILE"></V>
    	<V n="TEMPLATE IMAGE"></V>
    	<V n="MIN_TYPES">0</V>
    	<V n="MAX_TYPES">0</V>
    </P>
  5. Use the Read method, Write method, and the XML property to export the document hierarchy to an external location, which can be a content repository, a database, or a web server. This example exports the document hierarchy to a temporary location on a local server:
    m_oDCO.Read("C:\\C:\\Datacap\\NEW\\dco_NEW\\NEW.XML");
    strDCOXml = m_oDCO.XML;
    m_oDCO.Write ("c:\\temp_location\\new_application.xml")
    The Read method stores the document hierarchy in a setup object. The XML property assigns the XML file to a variable, and the Write method writes the document hierarchy (setup DCO) to a new location.