XML technologies / XML / XML in a Nutshell / XML as a document format / OpenOffice
(Excerpt from “XML in a Nutshell” by Elliotte Rusty Harold & W. Scott Means)
You can write markup manually in a text editor, but many nonprogrammers prefer a friendlier WYSIWYG-style approach. Ordinary word processors can save XML; Microsoft Word 2003 and OpenOffice.org Writer already do. Harold used Writer to write a considerably shorter XML book, Effective XML, published by Addison Wesley.
Note: Looking back, I regret the decision. If rewriting the book, I would write XML by hand, as with Processing XML with Java, rather than use OpenOffice. Good GUIs improve productivity, but bad ones hinder it. A GUI does not guarantee ease of use.
Scott and I wrote this book in Microsoft Word, mainly because it predated other high-quality XML authoring tools. We regret that too. Starting again, we would use DocBook.
The following code shows a simple OpenOffice document, again using text from this book, “XML in a Nutshell.” It differs in several ways from TEI and DocBook; for example, it uses namespaces, unlike TEI and DocBook. Book title and author names are absent because they live in a separate metadata document. Indexes and contents are generated from structure, content and markup rather than explicitly inserted. Most unusually, there are no section elements: chapters, sections and subsections at different levels use the element text:h. A section includes everything up to the next element text:h of the same level. Less obviously, this format is more general: it handles other OpenOffice document formats, including charts and tables, as well as narrative text.
<!DOCTYPE office:document-content PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
<office:document-content xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:fo="http://www.w3.org/1999/XSL/Format" office:class="text" office:version="1.0">
<office:script/>
<office:font-decls>
<style:font-decl style:name="Courier" fo:font-family="Courier" style:font-pitch="variable"/>
<style:font-decl style:name="Times" fo:font-family="Times" style:font-pitch="variable"/>
<style:font-decl style:name="Helvetica" fo:font-family="Helvetica" style:font-family-generic="swiss" style:font-pitch="variable"/>
</office:font-decls>
<office:automatic-styles>
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="ChapterLabel" style:master-page-name="First Page">
<style:properties style:page-number="0"/>
</style:style>
<style:style style:name="T1" style:family="texstyle:parent-style-name="WW-Comment Reference">
<style:properties fo:color="#000000"/>
</style:style>
<style:style style:name="T2" style:family="text" style:parent-style-name="emphasis">
<style:properties fo:language="none" fo:country="none"/>
</style:style>
<style:style style:name="T3" style:family="text">
<style:properties fo:language="none" fo:country="none"/>
</style:style>
</office:automatic-styles>
<office:body>
<text:sequence-decls>
<text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
<text:sequence-decl text:display-outline-level="0" text:name="Table"/>
<text:sequence-decl text:display-outline-level="0" text:name="Text"/>
<text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
</text:sequence-decls>
<text:p text:style-name="ChapterTitle">Einführung in XML</text:p>
<text:p text:style-name="Standard"></text:p>
<text:p text:style-name="ChapterTitle">XML als Dokumentformat</text:p>
<text:p text:style-name="Standard">XML ist vor allen Dingen ein Dokumentformat. Es war immer für Webseiten, Bücher, wissenschaftliche Artikel, Gedichte, Kurzgeschichten, Reerenzhandbücher, Anleitungen, Lehrbücher, Plädoyers, Verträge, Gebrauchsanweisungen und andere Dokumente gedacht, die von Menschen gelesen werden. Sein Einsatz als Syntax für Computerdaten in Anwendungen wie Bestellabwicklung, Objektserialisierung, Datenbanken sowie elektronischen Datenaustauschsystemen ist eigentlich nur einglücklicher Zufall.</text:p>
<text:h text:style-name="Heading 1" text:level="1">Das Vermächtnis von SGML####SGMLs Erbe !?###</text:h>
<text:p text:style-name="Standard"></text:p>
<text:h text:style-name="Heading 1" text:level="1">TEI</text:h>
<text:p text:style-name="Standard"></text:p>
<text:h text:style-name="Heading 1" text:level="1">DocBook</text:h>
<text:p text:style-name="Standard">DocBook <text:alphabetical-index-mark text:string-value="DocBook" text:key1="narrative-orientierte XML-Dokumente"/><text:s/><text:alphabetical-index-mark text:string-value="DocBook"/>ist eine SGML-Anwendung, die für neue Dokumente, jedoch nicht für alte entworfen wurde.Sie ist besonders bei Computer-Dokumentationen gebräuchlich. Verschiedene O'Reilly-Bücher wurden in DocBook geschrieben, einschließlich <text:alphabetical-index-mark text:string-value="Walsh, Norman"/>Norm Walsh und Leonard <text:alphabetical-index-mark text:string-value="Muellner, Leonard"/>Muellner's <text:span text:style-name="emphasis">DocBook: The Definitive Guide</text:span>. Es sind keine besonderen Werkzeuge notwendig, um Dokumente in diesem Format zu schreiben. Ein Großteil des Texts des Linux Documentation Projects (LDP) ist in DocBook geschrieben.</text:p>
<text:p text:style-name="ChapterTitle">XML im Web</text:p>
<text:p text:style-name="Standard"></text:p>
</office:body>
</office:document-content>Code example: An OpenOffice document
This is only part of what OpenOffice saves, cleaned up for presentation. It bundles related XML documents in a zip file. Unzip it before working with raw XML; the document shown here is in the file content.xml. Other XML files hold styles, metadata and settings. They could all be combined in one element office:document, but usually are not. The separation of content and presentation is a useful feature.
Nevertheless, OpenOffice is more presentation-oriented than DocBook or TEI. That suits WYSIWYG word processing but complicates processing with tools such as SAX, DOM and XSLT. Processing is possible, but markup provides fewer content-oriented clues. Essentially there are only headings, paragraphs, lists and tables; the latter two are absent here. Compared with DocBook and TEI, semantic information is limited and much is hidden in presentation rather than element names. Had the authors used direct italics, bold and Heltvetica formatting instead of named character styles, that information would have been almost irretrievably lost.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML in a Nutshell” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top