hi,
I am in need to convert the XML file in to appropriate java runtime objects..
For example:
<Information>
<Person>
<Name>XXX</Name>
>Number>243</Number>
</Person>
<Address>
<Add1>Church street</Add1>
<Add2>Church street</Add2>
</Address>
</Information>
If I give this input file as input, the Objects of type Person and Address is desired to be filled with data and come out as output. Is there any way to do it?? are there libraries already available???
Would be grateful if you guys reply to this message.
regards,
ramnath.
-
XML to runtime java objects- dynamic conversion? (8 messages)
- Posted by: Ramnath Putta
- Posted on: January 15 2003 11:01 EST
Threaded Messages (8)
- XML to runtime java objects- dynamic conversion? by Weston Aiken on January 15 2003 12:28 EST
- XML to runtime java objects- dynamic conversion? by Lasse Koskela on January 15 2003 15:21 EST
-
XML to runtime java objects- dynamic conversion? by Ramnath Putta on January 17 2003 11:14 EST
-
XML to runtime java objects- dynamic conversion? by Craig Collings on January 17 2003 06:42 EST
- castor!!!!! by J2EE DISCUSSION ANIL LINGUTLA on January 20 2003 10:46 EST
-
XML to runtime java objects- dynamic conversion? by Craig Collings on January 17 2003 06:42 EST
-
XML to runtime java objects- dynamic conversion? by Ramnath Putta on January 17 2003 11:14 EST
- XML to runtime java objects- dynamic conversion? by Lasse Koskela on January 15 2003 15:21 EST
- XML to runtime java objects- dynamic conversion? by Gal Binyamini on January 15 2003 19:21 EST
- XML to runtime java objects- dynamic conversion? by Vivek Rai on January 16 2003 10:57 EST
- XML to runtime java objects- dynamic conversion? by vimarsh vasavada on January 20 2003 04:04 EST
-
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Weston Aiken
- Posted on: January 15 2003 12:28 EST
- in response to Ramnath Putta
Why not DOM? -
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Lasse Koskela
- Posted on: January 15 2003 15:21 EST
- in response to Weston Aiken
Why not SAX?
No, seriously, I'd suggest you lookup some SAX parsing tutorial and code a handler class, which populates the whatever-objects. There's probably sample code which is very close to what you need... -
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Ramnath Putta
- Posted on: January 17 2003 11:14 EST
- in response to Lasse Koskela
Good to hear from you. Thank you very much Gal and Vivek. Both the libraries suggested by you was really useful to me. The class
JOXBeanBuilder class from the project (http://www.wutka.com/jox.html) exactly does what I want :).
and ofcourse the method
Object readObject(Class obClass)
forms the dynamic instance of the class template input, using the XML file supplied. Excellent and powerful.
I have one more small issue... This JOXBeanBuilder fills the value in to the bean using its getter and setter method at runtime. Out of curisoity, I want to know, if such kind of builder is available for normal classes also (my current classes are in these forms :( ..possibly you can treat those classes as a kind of structures in C which does nothing except to hold the data).
Thanks again. -
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Craig Collings
- Posted on: January 17 2003 18:42 EST
- in response to Ramnath Putta
Actually, the runtime representation of an XML document (or fragment) should probably not be DOM.
If you plan to use the object more than once, a DOM instance requires that its handlers burrow down the node tree searching for Strings in each case. If the object is to be used extensivley this is a maintainence nightmare (someone changes the name of an attribute and _you_ have to chase down all the occurences of that String).
A better approach in my opinion is to maintain a tight object binding as the xml comes in the door. The problem with this is its lack of generality - every type of document, or fragment of document, that you will be able to handle must be determined in advance.
So what I would do is write a generic data-bean factory to convert an XML heirarchy into a data-bean. Whether you use containment (one bean per element) or some more efficient optimisation, you can then use the bean without the code-rot that passing DOMs throught system engenders.
Alternatively, if you are writing over the wire from java to java, you could prepare data-beans to send, then use the standard java.beans.XMLEncoder and java.beans.XMLDecoder to write and read the beans to and from XML. -
castor!!!!![ Go to top ]
- Posted by: J2EE DISCUSSION ANIL LINGUTLA
- Posted on: January 20 2003 10:46 EST
- in response to Craig Collings
thats right, best for data binding. castor.org -
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: January 15 2003 19:21 EST
- in response to Ramnath Putta
-
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: Vivek Rai
- Posted on: January 16 2003 10:57 EST
- in response to Ramnath Putta
Check this out this might be helpful to u .
http://www.wutka.com/jox.html
This does excatly the same u want to achieve. this site references some other work on the same line.
hope this helps.
Regards
Vivek -
XML to runtime java objects- dynamic conversion?[ Go to top ]
- Posted by: vimarsh vasavada
- Posted on: January 20 2003 04:04 EST
- in response to Ramnath Putta
Hi,
You can use Castor. This is very commonly used for java object and xml binding, and the best part is its an opensource.
Cheers