Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using XML Java Class Generator, 8 of 8
This section lists XML Java Class Generator questions and answers.
I used XML Java Class Generator to generate some class files for a sample DTD schema. On looking at the classes generated, I saw only APIs to construct instances through regular means (providing values to members) and APIs to print the XML representation to an outputstream. The functionality is not as complete as I expected it to be. I expected the document class to include a constructor that will take an XML document object and populate the various members automatically.
Does this functionality exist?
XML Java Class Generator does not have this functionality at this time as only the XML Parser for Java can build DOM trees.
I want to use XML as the storage medium for meta-data. This meta-data consists of complex, nested structures for which XML is well suited. At system start-up time I need to have access to all these meta-data objects as first class Java objects.However, I don't want to have to write custom code to run atop an XML parser such as Oracle XML Parser to build instances of these objects (one XML file -> one instance).
My ideal interface looks like this:
DTD/XML Schema + XML files fed to an XMLClassGenerator (runs atop an XMLParser) spits out Java source code that instantiates my meta-data object.
For example, if I have a meta.dtd (schema) and meta.xml which I want to map to a Meta.java.class Meta {public String metaName;public int numMeta;public Date dateMeta;};
I want to be able to run XMLClassGenerator on meta.dtd (schema) and meta.xml and get this kind of source code output:
MetaBuilder.javaclass MetaBuilder {public init() { Meta metaInstance = new Meta(); metaInstance.metaName = "Example1"; metaInstance.numMeta = 1; metaInstance.dateMeta = new Date("07/16/1999");}
Do you plan to extend the Class Generator capability to do this? I can use this to send Java objects across a network, instead of an XML document over RMI.
I also am not aware of a direct solution out there. This would be an interesting extension for our Class Generator.
In transcribing the code for the DTD Class Generator code form an article, I encountered an error I do not know how to correct. The program attempts to instantiate an XMLParser object, whose class is defined as abstract. What child classes of this class would work for running the code?
XMLParser was concrete in our V1 XML Parser. It's now abstract in V2 and you must either construct a DOMParser or a SAXParser. The article is probably using a DOMParser.
What steps install XML Java Class Generator?
There are basically two steps:
What does the XML Class Generator for Java do?
The XML Class Generator for Java creates Java source files from an XML DTD. This is useful when an application wants to send an XML message to another application based on an agreed-upon DTD or as the back end of a web form to construct and XML document. Using these classes, Java applications can construct, validate, and print XML documents that comply with the input DTD. The Class Generator works in conjunction with the Oracle XML Parser for Java v2, which parses the DTD and passes the parsed document to the class generator.
How do I use the XML Class Generator for Java to get XML data?
First, get the data from the database using JDBC ResultSets. Then, instantiate objects using the classes generated by the XML Class Generator.
Can I automatically instantiate objects based on an XML file?
Presently, you can only use DTD to generate classes and then instantiate each object by calling the create methods in the class. Please contact us if you have a business need to use XML file to instantiate objects automatically.
Does XML Java Class Generator support any kind of DTD?
Yes, it supports any kind of DTD that is XML1.0 compliant.
How do I fix the classes-not-found errors?
To fix the classes-not-found error, include classgen.jar and xmlparserv2.jar in your CLASSPATH.
I've generated, from a DTD, a set of Java classes with "ClassGenerator". After, I've tried to create a Java application that uses these classes to create an XML file from data passed as arguments. I cannot create the root object, the object derived from CGDocument, more than one time because I obtain the following error message :
oracle.xml.parser.XMLDOMException: Node doesn't belong to the current document
How do I handle the star operator (*). When the application starts I do not know how many times the element will appear. Thus I do not build a static loop where I make a sequence of "element.addNode()". The problem is that some of these will be empty and I will obtain an XML document with a set of empty elements with empty attributes.
You can create subsequent XML docs by calling the constructor each time. A well-formed XML document is not permitted to have more than one root node, therefore you cannot use the "*" on the element you are designating as the document root.
I want to create an XML file using the DOM API. I dont want to create the XML file by typing in the text editor
<xml> <future>is great</future> </xml>
instead, I want to create it using the DOM API. I do not know how to start! There are several examples of manipulating an XML file using the DOM once there is an input file, but not the other way round. That is, of creating the XML file from scratch (when there is no input file) using the DOM, once you know the "tagnames" and their "values".
The simplest way is download XML Class Generator for Java and give it a DTD of the XML document you want. It will create the DOM classes to programmatically create XML documents. There are samples included with the software.
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|