Adding and replacing documents and versions
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).
TextmlserverError [] err =
ds.SetDocuments(docList, Constants.TEXTML_ADD_DOCUMENT |
Constants.TEXTML_REPLACE_DOCUMENT |
Constants.TEXTML_INDEX_DOCUMENT,
Constants.TEXTML_DOCUMENT);
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:
TextmlserverError [] err =
ds.SetDocuments(docList, Constants.TEXTML_ADD_DOCUMENT |
Constants.TEXTML_CREATE_NEW_VERSION |
Constants.TEXTML_INDEX_DOCUMENT,
Constants.TEXTML_DOCUMENT);
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.
- 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.
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);