Frequently asked questions - General
LibreOffice and XML
You've with no-doubt often heard of XML, heard that the LibreOffice file format was XML, but what exactly is it and especially what it means, what in the end is XML?
- 1 LibreOffice and XML
- 1.1 What is XML?
- 1.2 Why XML?
- 1.3 The XML in LibreOffice
- 1.4 Which LibreOffice module use XML?
- 1.5 DTD, XML schema, XSLT... what is this?
- 1.6 OASIS
What is XML?
This acronym stands for eXtensible Markup Language.
XML is part of the class metalanguages, it is actually a subset of SGML. Okay, so what is the SGML (Standard Generalized Markup Language)? It is a language that allows you to create structured and modular documents. Concretely this means that you can create a document from data as diverse as sound, data from a database or text and images. SGML has been defined for a wide range of applications and must be kept on a very long term. This language is quite extensive and complex, the XML was created to simplify SGML.
What can be confusing at first, is that the HTML is very similar to XML. It is a language with tags that open and close. Big difference though, HTML was defined with tags that describe the presentation, while the XML tags deal with the content. But yes, HTML is a subset of SGML, but only for processing data on the Web.
If one summarizes the XML is a clear way (and not a programming language or a new HTML) for structuring, describing and exchanging data. The content and the layout are separated to permit the exchange. The content can then be reused in other forms or other media. Data can be of all kinds: chemical formulas, financial data, music data, text ...
An example of the xml content of a LibreOffice document :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE office:document-meta PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd"> <office:meta> <meta:generator>LibreOffice/3.3$Win32 LibreOffice_project/330m18$Build-4</meta:generator> <meta:initial-creator>Sophie Gautier</meta:initial-creator> <meta:creation-date>2011-01-12T19:07:36</meta:creation-date> <meta:document-statistic meta:table-count="0" meta:image-count="31" meta:object-count="0" meta:page-count="17" meta:paragraph-count="213" meta:word-count="2647" meta:character-count="16353"/> </office:meta>
You see the tags <> distinguish the document content. An open tags must always be closed: <office:meta> will be completed by </office: meta> To add information to the document, we give it attributes, always followed by a value meta:page-count="17". The meta:page-count attribute has the value "17" (document has 17 pages). We can also put comments like this:
If you look at the XML snippet above, there are some things that surprise:
- XML is readable by yourself, but also by the machine. This is one of its great advantages.
- It is Unicode (Unicode: a unique number is defined for every character, regardless of platform, language, program). This means it can be stored in different encoding. What's the difference? You probably know that the documents were (still are) encoded in ASCII, but it only refers to one alphabet and one writing system. The code fragment shows a UTF-8 encoding, which is supported by many alphabets.
- The XML is object-oriented: instead of breaking down the data into normalized tables linked by relationships, it describes objects (concrete and abstract) by modeling their properties as they are, which makes the XML documents more intuitive to understand .
- Finally, the XML distinguishes between the content and the layout, the layout of the data being provided by third-party languages such as CSS, XSL ...
- The XML generates a low cost in terms of software components, hence its successful integration into the IT industry.
The XML in LibreOffice
And how do you see that LibreOffice is XML? LibreOffice has a .xml native file format compressed. This means that the files that make up your LibreOffice document are encapsulated in an archive. An example: take your favorite unzip tool (see What is the format of LibreOffice?) and open any LibreOffice file. You will see a collection of different files, some of which have the .xml extension.
Which LibreOffice module use XML?
All LibreOffice modules use XML as its native file format. Math module uses a package structure a little different, but some xml inside the package: MathML is an XML standard for formulas. Also, some configuration files use XML. These files structure will always be there:
- The meta.xml contains information about the document (author, date of last backup).
- The styles.xml contains the styles used in the document
- Content.xml contains the main document content (text, pictures, graphics ...)
- Settings.xml, usually specific to an application, contains some parameters such as the selected printer...
- TheMETA-INF/manifest.xml contains additional information about other files (such as the MIME type or encryption).
The images are saved in the native format inside the zip. Now you understand why LibreOffice files take up so little space on your hard disk!
To learn more about LibreOffice file formats, see http://xml.openoffice.org website.
Note that an XML document can not be displayed as it is, it needs a transformation language (XSLT) and a formatting language for objects (XSL-FO) to be able to display all the information correctly (eg need: if your document is made up of various parties organized separately or if it contains a table with formatting ...)
DTD, XML schema, XSLT... what is this?
DTD Document Type definition
The DTD will specify which elements and attributes will be used in the XML document and will describe its structure and content. The DTD can be internal to the document (it includes the definitions in the document itself) or external (it is located in a local file or called by URL). The XML standard does not mandate the DTD, and we talk about XML document if it has a valid DTD or XML document well-formed if it does not include (but he respects the XML standard).
Example of content of LibreOffice DTD
List the initial writers in this form (with initial="true"). Initial Writers is a term from the PDL (License). If one of these authors assigned copyright to somebody else, e.g. the company they are working for, use the attribute copyright="..." and name the copyright holder. --> <!ELEMENT authors ( author+ ) > <!ELEMENT author (#PCDATA)> <!ATTLIST author id ID #REQUIRED initial CDATA #IMPLIED email CDATA #REQUIRED> <!--
A schema also defines the structure of an XML document, however, it is more flexible than a DTD to define element types. It uses the acquired DTD to define the models. Schemes are subject to a W3C specification.
XSLT : eXtensible Style Language Transformation
It is a programming language for transforming XML documents into other forms, such as RTF, HTML or PDF, etc.. This language is declarative and non-procedural (no algorithm), which makes it easier to access for non-developers. Itself written in XML, it can be reinterpreted. In fact, XSLT transforms the XML tree into rules of models describing a style sheet. It is often compared to CSS because as CSS it produces such rules, the order of appearance of these rules does not matter in the document, it also has priority when multiple rules may apply. The difference is that if a CSS is empty, it will not affect the html generated document, it will simply be ignored being only a layout, while the XSLT will generate an empty document (actually, this is not entirely true because the specification has defined internal rules still present, so the document is never really empty :). A very good site, full of resources and XSLT filters for use with LibreOffice: http://www.maxopeninfo.com/
This is the declarative language associated to XSLT that allow to define paths location within the XML tree.
XSL-FO : eXtensible Style Language for Formating Object
Language for defining generic objects presentation (such as lists, tables ...) often used for PDF output. It comes after an XSLT transformation and allows a visual interpretation of the processed objects.
Oasis (Organisation for the Advancement of Structured Information Standard) is a global consortium that drives the development, convergence and adoption of standards for e-business. It therefore defines the XML standard. This definition is based on the LibreOffice file formats, they are open and consistent with a published DTD. More information can be found here: http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=office