3 How to use external (XML-)editors to edit X-Hive/DB documents

This article describes the unsupported FTP-and DAV services that can be used to handle the documents that reside in the database with FTP or DAV aware programs.

After an introduction, we describe some issues with using these services.

3.1 Introduction and usage

In certain cases you may want to edit XML documents in the database with an external editor. We provide two services for this:

Both of these services come with full source code, so that they can be modified to match your environment. After you have started one of these servers, you can access them through FTP and DAV-clients. Here are some examples of such clients: For Windows Network Places and XML Spy, URLs for accessing an FTP-server should look like ftp://localhost/ and for accessing a DAV server (with standard Tomcat settings) would be http://localhost:8080/xhivedav (where localhost is the hostname of the machine running the server).

3.2 Dealing with DTDs, example

This section and the next are only interesting if you want to use the combination of WebDAV (or FTP) and DTDs.

In some cases, you will want to use DTDs connected to the documents in the database from the external editor. This is especially the case with an editor like XMetaL, where a DTD is required to be able to edit the document properly. In X-Hive/DB, the connection between a document and a DTD is made very different from how its done on a file-system. In X-Hive/DB the DTDs are located in a catalog, and identification is done through the Public ID in the doctype declaration. Since the DAV/ FTP servers offer up the libraries and documents as folders and files, DTDs must be located through a file location.

The next section will go into detail about how we solved this problem. However, we will start with a usage example (the sample will use WebDAV, references to XMetaL imply XMetaL 4.0 or better):

3.3 Dealing with DTDs, explained

Note:

The information in this section is mostly targeted towards X-Hive/DB 4.0/5.0 and at least version 1.5 of our WebDAV integration (your mileage with earlier versions may vary).

This section describes how we worked around the problems of using DTDs that are stored within X-Hive/DB, for which an example of usage was given in the previous section..

In X-Hive/DB, every library has access to a catalog (available through XhiveLibraryIf.getCatalog()). That catalog holds a list of stored DTDs. Documents may refer to DTDs in this catalog. This referring is through the the public id in the document type declaration, and the system id in the document type is not used for this.

When parsing with validation, a DTD will also be stored in the catalog, unless a DTD with the same public-id is already in the catalog (if that is the case, the document is validated against that DTD). You can also store a DTD explicitly (through the Abstract Schema interfaces).

With File-based editors, DTD resolution is done based on the file-location specified in the system id of the document type declaration. This can be a relative path. When you present the database as files and folders, and you want the DTD be found, it must be found as a file in some folder, you cannot simply follow the link made in the database. The remainder of this section describes what solution we have taken to implement this, but that solution can best be described as 'a hack'. It could be that in your specific situation another method could work better, in which case you can change the sources. Also, this section describes the general technique, the actual implementation may be different in different versions of the servers.

When you store a file, it parses the document without validation (because some documents may not have a DTD specified for it, and then validation is not possible), which means a DTD is not stored nor is a DTD attached to the document. However, when there is a doctype definition the DTD is still read, as it may contain entity definitions. Therefore, if you have a doctype definition in a document you want to save, or (for WebDAV) you must specify the full location of the DTD as the system id. After the XML document is parsed, the newer versions of the servers will try to find a DTD in the catalog linked to this document based on the public id (or the full system id if it was found), and if one can be found it will be linked to the document in the database. This is done with DocumentAS.setActiveASModel.

When you retrieve a document from the database later, and the DTD was linked to the document as described above, the public id and system id of the document type declaration may have to be changed to now point to the local path.

What we have done is made the catalog available as a folder in each library (whether that library has a local catalog or not). This folder is virtual, in the sense that it is simply added by the server process to the list of file- and directory-names. The name is therefore also arbitrary (xhive-catalog), and can be changed in the sources. When a document is loaded from the database to a DAV/ FTP client, that client may use the system id to look up the DTD. To be able to find the DTD in the database, the system id must then be a relative path, with a format like xhive-catalog/fileName.dtd. In that case the client will request the server for a file fileName.dtd in a folder xhive-catalog relative to the library where the document is found. When the server gets such a request, it will know to look in the catalog, and send the DTD to the client over the network. To get the system id to hold a string of the described structure, you can for instance set it correctly when you first parse the document. When you retrieve the document, the method XhiveDocumentIf.fixupDoctypeIds is used to set this information correctly for the server (so the data is changed!).

So in short, with the default way we provide these servers the following is the case:

3.4 Other Caveats