[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to store/retrieve XML Documents in Ozone?
Wed, 27 Oct 1999 Ann Tecklenburg wrote:
>I see that we now have the XML DOM classes
>in the source tree, but I am not sure as how to best use
>them.
There are two ways to use PDOM in ozone:
1. Directly use an XML-Parser to create OzoneObjects (Elements, etc)
For this you have to modify the XML-Parser to create OzoneObjects
instead of their own DOM-Implementation. I used that with OpenXML,
but there are a _lot_ of changes in the parser source, because there
is no parser spec to change the DOM-Factory from OpenXML to the
ozone factory. So this is only for testing, but its more faster
then the 2nd solution which is more elegant than the described.
2. The second way is to convert a given DOM to ozone-DOM. For this I
wrote something like a DOM-Converter (org.ozoneDB.xml.util.DOMConvertUtil.java)
The converter goes through the DOM-tree an creates an OzoneObject
for each found DOM-node. You can use every W3C compliant DOM-Parser
like XML4J or OpenXML. I added a small Parser interface to allow
integration of other parsers as well..
This is a small piece of code to demonstrate the DOM-Converter
<------------------->
Parser parser;
DOMConverterUtil converterUtil;
Document doc;
RemoteDatabase database = new RemoteDatabase();
// create a parser of your choice
parser = (Parser) Class.forName("org.ozoneDB.xml.util.IBMXMLParser").newInstance();
// parser = (Parser) Class.forName("org.ozoneDB.xml.util.OpenXMLParser").newInstance();
// open the connection on localhost at port 3333
database.open ("localhost", 3333);
// reload our database classes if we changed them
database.reloadClasses();
converterUtil = new DOMConverterUtil ();
// open the real DOM converter (ozone object) through the helper class
converterUtil.openConverter (database);
//
doc = converterUtil.convertDOM (parser.parse (
new InputStreamReader (
new FileInputStream (
new File ("test.xml")))));
// closing the converter means deleting the ozone converter object too
converterUtil.closeConverter ();
<-------------------->
>Lets say I have a something that contains a valid XML Document and can be
>turned into an input stream, say a String, File, or whatever, how do I store
>and retrieve them to an OzoneDb? If I create a Java class that contains a
>DTDDocument member, does Ozone automatically do the internal conversion or
>do I need to do the convert call directly?
Now you have a W3C-compliant Document (doc) which you can name to retrieve
it later time (database.nameObject ((..)doc, "myName") - attention, there is
a bug in nameObject()! - so this is just the theory :-))
To retrieve the stored document you have to use
database.objectForName("myName"); If you get an OzoneObject back, you can
go through the DOM-tree with W3C-DOM-API (getFirstChild(), getnextSibling()...)
At this time there is a bug in ozones PDOM implementation, the DOM-Converter
canĀ“t convert XML nodes with attributes. But I will check this asap.
Regards,
Lars
--
________________________________________________________________
Lars Martin lars@softwarebuero.de
softwarebuero m&b (SMB) http://www.softwarebuero.de