Adding and replacing documents and versions

To be able to create new versions of a document, version control must be enabled for the document base. See Enabling version control and setting default options
Note: Whatever the version control default options, we recommend overriding them when adding (or replacing) a document to the document base. To override the default options, call a two- or three-parameter version of method SetDocuments in class IxiaDocumentServices: the second parameter contains the version control flags (as well as other flags).

In Adding documents to a document base, we show how to add documents to a docbase for which version control was disabled. Here is the code snippet that adds the document objects stored in doclist:


// Add the documents to the docbase.
// Index the documents. (Only XML files are indexable.)
// If a document with the same name already exists in the docbase,
// then replace the old document with the new one.
// The documents are all of type "user document" (i.e., they are
// not "system documents").

IxiaTextmlServerError[] err =
    ds.SetDocuments(docList,
                    TextmlConstants.TEXTML_ADD_DOCUMENT |
                    TextmlConstants.TEXTML_REPLACE_DOCUMENT |
                    TextmlConstants.TEXTML_INDEX_DOCUMENT,
                    TextmlDocumentType.TextmlDocument);

The above snippet behaves like this:

For each document object in doclist:

  • If the docbase does not contain a document with the same name as the document object:
    • Adds the document object to the docbase as a new document.
  • If the docbase already contains a document with the same name as the the document object:
    • Replaces the existing document with the document object.

With version control enabled, you need to change the version control flags:

IxiaTextmlServerError[] err = 
    ds.SetDocuments(docList,
                    TextmlConstants.TEXTML_ADD_DOCUMENT |
                    TextmlConstants.TEXTML_CREATE_NEW_VERSION |
                    TextmlConstants.TEXTML_INDEX_DOCUMENT,
                    TextmlDocumentType.TextmlDocument);

The above snippet behaves like this:

For each document object in doclist:

  • If the docbase does not contain a document with the same name as the document object:
    • Adds the document object to the docbase as a new document.
  • If the docbase already contains a document with the same name as the the document object:
    • Stores the document object in the docbase as a new version of the existing document.

Flags you can always set:

  • TEXTML_ADD_DOCUMENT: Normally adds the document object as a new document. But if there is an existing document with the same name, then the method call's behavior depends on the other flags that are set.
  • TEXTML_REPLACE_DOCUMENT: Normally replaces an existing document in the docbase. But if there is not an existing document with the same name, then the method call's behavior depends on the other flags that are set.
  • TEXTML_INDEX_DOCUMENT: Mark all documents in the document list as indexable. If a document is indexable, then whenever TEXTML Server indexes the docbase, TEXTML Server will index the document's content.
Additional version control flags you can set only with version control enabled:
  • TEXTML_CREATE_NEW_VERSION: The document object is added, not as a separate document in the docbase, but as the current version (i.e., the newest version) of the existing document. The previous version is retained in the docbase.
  • TEXTML_REPLACE_CURRENT_VERSION: The document object replaces only the current version of the existing document.
  • TEXTML_PURGE_OLDEST_IF_LIMIT_REACHED: If preserving the previous version will cause the document to exceed the docbase's limit (for the number of previous versions of a document), then:
    • If this flag is set, the oldest version of the document is deleted from the docbase.
    • If this flag is not set, the method call fails.
Note:

If you want to set documents according to the default options of the docbase, then call one of the one-parameter overloaded versions of method SetDocuments:

// Set the documents in <doclist> according to the docbase's default options:
IxiaTextmlServerError[] err = ds.SetDocuments(docList);