DOM4J in Ozone

Per Nyfelt

Ozone Documentation License, Version 1

This document is free software; you can redistribute it and/or modify it provided that the terms of the GNU Library General Public License as published by the Free Software Foundation version 2 of the License; and the following terms are met.

The Ozone Database Project <ozone@ozone-db.org>

Included in the ozone distribution is code and documentation made available by other copyright holders and under different licenses. All these licenses allow worldwide, royalty free distribution, whether alone or as part of a larger product. License, copyright and disclaimer of this software is included in this directory.

The document is Copyright (C) 1997-2003 by SMB GmbH, Rohrteichstr. 18, 04347 Leipzig, Germany, All rights reserved.

You must give prominent notice with each copy of the work that the document is used in it and that its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License.

The name ozone must not be used to endorse or promote software products derived from this software without prior written permission of SMB.

Software products derived from this document may not be called ozone nor may ozone appear in their names without prior written permission of SMB.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

Abstract

This document describes how to get started with using the dom4j based xml module in Ozone.


Table of Contents

Introduction
Overview
Design ideas

Introduction


Table of Contents

Overview
Design ideas

There are some slight deviations from the official DOM4J stuff i.e.three classes are changed from concrete classes into interfaces with an implementation class. The three classes are (DocumentFacotor, NameSpace and QName). My hope is that this modification will be included in the offical dom4j API but regardless of the outcome anyone familiar with DOM4J or JDOM should be able to use it within minutes.

Basically the idea is as follows: When working from the client side use the OzoneDocumentHelper to create XML e.g.

Parse a file:

	OzoneDocumentHelper.configure(ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333"));
	Document doc = OzoneDocumentHelper.parse(new FileReader(file),
	"theXMLObjectName");
	

Build up a document from scratch:

	OzoneDocumentHelper.configure(ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333"));
	Document doc = OzoneDocumentHelper.createDocument("testDoc");
	Element root = OzoneDocumentHelper.createElement("addresses");
	doc.setRootElement(root);
	Element el1 = OzoneDocumentHelper.createElement("address");
	el1.addAttribute("name", "Andreas");
	Element town1 = OzoneDocumentHelper.createElement("town");
	town1.setText("New York");
	el1.add(town1);
	root.add(el1);
	String docXML = doc.asXML();
	
When working with the API from within the server you use the DocumentFactory directly e.g.
	PersistentDocumentFactory factory =
	OzoneDocumentFactoryImpl.getInstance(database());
	Document doc = factory.createDocument();
	Element root = factory.createElement("foo");
	doc.setRootElement(root);
	root.addAttribute("name", "per");
	root.add(factory.createElement("foo").addComment("bla bla"));
	
etc. etc.