Nl:Een XML-bestand aanmaken

From Gramps
Revision as of 09:38, 30 July 2007 by Erikdr (talk | contribs)
Jump to: navigation, search


GRAMPS en XML

GRAMPS kan een XML-bestand importeren en exporteren. Dit XML-bestand bevat alle informatie van het gegevensbestand. Dit XML-bestand is zeer bruikbaar om gegevens van de ene computer naar te andere over te zetten of om XML-bewerkingen uit te voeren.

Aanmaken van het XML-bestand

De eenvoudigste manier om een XML-bestand aan te maken is de gegevens te exporteren. Dit kan je doen door gebruik te maken van het Bestand->Exporteren menu. Zo wordt een bestand aangemaakt met een .gramps extensie. Dit bestand is gewoonlijk een gezipt XML-bestand. Dit hangt echter af van een aantal systeeminstellingen. Zo kan het XML-bestand ook ongecomprimeerd opgeslagen worden.

Gramps drukt het bestand samen omdat XML-bestanden vrij groot kunnen worden. Voor grote gegevensbestanden kan de grootte oplopen tot méér dan 100 Mb. Gelukkig kunnen deze bestanden goed samengedrukt worden zodat de bestandsgrootte wel meevalt.

Hoe weet je of het XML-bestand samengedrukt is?

Het eenvoudigste is om de file opdracht uit te voeren.

 $ file data.gramps

Is het bestand samengedrukt, dan zie je als resultaat iets in de zin van:

 data.gramps: gzip compressed data, from Unix, last modified: Sun Jun 17 22:36:04 2007

Is het bestand niet samengedrukt, dan zie je:

 data.gramps: XML 1.0 document text

How do I uncompress the file?

If the file is compressed, you can uncompress it using the gunzip command.

 $ gunzip < data.gramps > data.xml

This example creates an uncompressed data.xml file from the compressed data.gramps file.

You must use the I/O redirection operators (">" and "<"), since gzip expects files to have a .gz extension.

I am confused. How do I extract editable XML from .gramps file?

You may download and run gramps2xml script. First make it executable:

  chmod +x gramps2xml

Then run it like so:

  ./gramps2xml filename.gramps filename.xml

Why doesn't GRAMPS just use a .gz extension?

GRAMPS uses the Shared Mime System defined by Free Desktop project, and used by all major desktops, including KDE and GNOME. GRAMPS relies on the MIME type identified by the Shared Mime System to determine the file type of the file.

The Share Mime System allows you to identify a file's type by either using a file extension or by looking at the contents of a small section of the file. The first problem is, usually the filename or extension pattern has the higher priority compared to the contents: if the file is named something.jpg then it is likely to be JPEG image, not text. So if the GRAMPS XML file had added .gz extension to the name, the Shared Mime system would tell us that the file's type is application/x-gzip instead of the expected application/x-gramps-xml. Unfortunately, it cannot tell us that it is a gzip'd GRAMPS XML file.

The second problem is, if we looked at the contents, we would not be able to tell the difference between a gzip'd GRAMPS XML file or any other gzip'd file. If we looked at uncompressed data, we would not be able to tell the difference between a GRAMPS XML file and other XML files. So again, the Shared Mime system could not tell us that it is a gzip'd GRAMPS XML file.

For these reasons, we must rely on the .gramps extension. If we don't, we would not be able to tell if this was a valid file. Even worse, the mime type of application/x-gzip would be associated with another application (such as File Roller or Ark) instead of GRAMPS. The mime type of application/xml may be associated with XML editors (Bluefish, Conglomerate, Emacs, etc). In that situation, the user double-clicking on the file in the file manager (or performing the default action for the type by any other means) will never launch GRAMPS with this data,

GRAMPS is not unique in this problem. For example, the OpenDocument format used by OpenOffice, KWord and AbiWord is actually a collection of files in a zip archive. If you run unzip on a OpenDocument file, you will see something like:

 $ unzip test.odt
 Archive:  test.odt
   inflating: mimetype                
   inflating: meta.xml                
   inflating: settings.xml            
   inflating: META-INF/manifest.xml   
   inflating: styles.xml              
   inflating: content.xml