Results 1 to 5 of 5
- 05-11-2011, 07:14 PM #1
Member
- Join Date
- May 2011
- Posts
- 13
- Rep Power
- 0
JAVA Object to XML to JAVA to XML
In one of my project below is my requirement:-
-Create input XMLs from Java class..
-Take input from user then store that data to Java object and submit for processing
-After processing print response java object again in XML.
What is the best API to achieve this. Will be helpful if any example is available.Last edited by buntyindia; 05-11-2011 at 07:17 PM.
- 05-11-2011, 07:33 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
- 05-14-2011, 08:33 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
If you are using Java Beans to hold the data, then you can use java.beans.XMLDecoder and java.beans.XMLEncoder.
- 05-15-2011, 07:16 PM #4
Member
- Join Date
- May 2011
- Posts
- 13
- Rep Power
- 0
Will it handle Iterative ArrayList Classes in XML generation?
Thanks for the Reply =)
I have a Java Object that have some fileds like arraylist<Class> will it take care of these fields as well ?
If that arrayList<Class> have another fields that can be normal fileds or arraylist of another class, will it take care of all fields during XML generation?
Example:-
Root Class have below fields
private int ArCt;
private ArrayList<ClassChild1> Ar;
......
Setters
......
Getters
ClassChild1.class
private int PlnCd;
private int cArCt;
private ArrayList cAr<ClassChild2> cAr;
ClassChild2.class
private String PlNm
XML Needed - Example from above object
<root>
<ArCt>1</ArCt>
<Ar>
<ClassChild1>
<PlnCd>S</PlnCd>
<cArCt>2</<cArCt>
<cAr>
<ClassChild2>
<PlNm>Plan1</PlNm>
</ClassChild2>
<ClassChild2>
<PlNm>Plan2</PlNm>
</ClassChild2>
</cAr>
</ClassChild1>
</Ar>
</root>Last edited by buntyindia; 05-15-2011 at 07:27 PM.
- 05-16-2011, 12:51 PM #5
i made a test with xstream
since this is the xml api i know (and also used in the persistence tutorial found in my signature). first i create some instances with:
Java Code:import java.util.ArrayList; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; class Root { private int ArCt; private ArrayList<ClassChild1> Ar; public Root() { // create arraylist for Ar Ar = new ArrayList<ClassChild1>(); // create one child1 ClassChild1 c1 = new ClassChild1(); ClassChild2 c2 = new ClassChild2(); c1.PlnCd = 10; c1.cArCt = 20; c2.PlNm = "PlNm of class ClassChild2"; c1.cAr.add(c2); Ar.add(c1); } class ClassChild1 { int PlnCd; int cArCt; ArrayList<ClassChild2> cAr; public ClassChild1() { cAr = new ArrayList<ClassChild2>(); } } class ClassChild2 { String PlNm; } public static void main(String[] args) { XStream xstream = new XStream(new DomDriver()); Root root = new Root(); System.out.println(xstream.toXML(root)); } }
i removed the access modifiers in the field so i can access them directly without getters and setters (bad practice!) and xstream generate this xml-output:
<root.Root>
<ArCt>0</ArCt>
<Ar>
<root.Root_-ClassChild1>
<PlnCd>10</PlnCd>
<cArCt>20</cArCt>
<cAr>
<root.Root_-ClassChild2>
<PlNm>PlNm of class ClassChild2</PlNm>
<outer-class reference="../../../../.."/>
</root.Root_-ClassChild2>
</cAr>
<outer-class reference="../../.."/>
</root.Root_-ClassChild1>
</Ar>
</root.Root>
as you can see, also composition and aggregation is provided by xsteam. please note, you can have absolute class references instead of ../..
Similar Threads
-
Java add flash object
By Dennis in forum Advanced JavaReplies: 0Last Post: 01-06-2011, 08:06 PM -
Operator < cannot be applied to java.lang.Object, Object
By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM -
how to insert a ole object using java
By ak88 in forum Advanced JavaReplies: 0Last Post: 01-05-2010, 03:26 PM -
Java Object Migration
By vijat in forum Advanced JavaReplies: 1Last Post: 10-23-2009, 01:18 PM -
need help about java class and object
By mrjohn007 in forum New To JavaReplies: 1Last Post: 01-28-2009, 05:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks