Solved

Java-XML

Posted on 2006-07-17
5
223 Views
Last Modified: 2010-05-18
Hi All,

I have a below XML using 3 DTO objects..

<?xml version="1.0" encoding="UTF-8"?>
<OrderDetails title="OrderDetails">
 <FirmBook>?</FirmBook>
 <BlockAccMnc>T25380</BlockAccMnc>
 <QuantityOnAllocations>11000</QuantityOnAllocations>
 <Date>Mon Jul 17 14:45:11 EDT 2006</Date>
 <TradeType>CA</TradeType>
 <OrderId>*</OrderId>
 <ClientID>65475</ClientID>
 <ProductType>EQ</ProductType>
 <ExecutionPoint>*</ExecutionPoint>
 <Currency>JPY</Currency>
 <BasePrincipalOnAllocations>61000</BasePrincipalOnAllocations>
 <ExecutionChannel>*</ExecutionChannel>
 <ExecutionCountry>JPN</ExecutionCountry>
 <FiI>32216031</FiI>
 <Price>5</Price>
 <GeneralProfile>*</GeneralProfile>
 <Overrides>*</Overrides>
 <Response>*</Response>
 <Quantity>5000</Quantity>
 <AllocationDetailsList>
  <AllocationId value="53187448">
   <SubAccMnc>T20202</SubAccMnc>
   <BasePrincipalOnExecutions>33000</BasePrincipalOnExecutions>
   <QuantityOnExecutions>6000</QuantityOnExecutions>
   <AllocationId>53187448</AllocationId>
   <Price>5</Price>
   <GeneralProfile>*</GeneralProfile>
   <Overrides>*</Overrides>
   <Response>*</Response>
   <Quantity>5000</Quantity>
   <ExecutionDetailsList>
    <ExecutionId value="SBALTSE?5.0">
     <AllocationBP>0</AllocationBP>
     <AllocationID>*</AllocationID>
     <AllocationQuantity>0</AllocationQuantity>
     <ExecutionId>SBALTSE?5.0</ExecutionId>
     <Price>5</Price>
     <GeneralProfile>*</GeneralProfile>
     <Overrides>*</Overrides>
     <Response>*</Response>
     <Quantity>3000</Quantity>
    </ExecutionId>
    <ExecutionId value="SBALOSE?6.0">
     <AllocationBP>0</AllocationBP>
     <AllocationID>*</AllocationID>
     <AllocationQuantity>0</AllocationQuantity>
     <ExecutionId>SBALOSE?6.0</ExecutionId>
     <Price>6</Price>
     <GeneralProfile>*</GeneralProfile>
     <Overrides>*</Overrides>
     <Response>*</Response>
     <Quantity>3000</Quantity>
    </ExecutionId>
   </ExecutionDetailsList>
  </AllocationId>
  <AllocationId value="53187454">
   <SubAccMnc>T20202</SubAccMnc>
   <BasePrincipalOnExecutions>28000</BasePrincipalOnExecutions>
   <QuantityOnExecutions>5000</QuantityOnExecutions>
   <AllocationId>53187454</AllocationId>
   <Price>6</Price>
   <GeneralProfile>*</GeneralProfile>
   <Overrides>*</Overrides>
   <Response>*</Response>
   <Quantity>6000</Quantity>
   <ExecutionDetailsList>
    <ExecutionId value="SBALTSE?5.0">
     <AllocationBP>0</AllocationBP>
     <AllocationID>*</AllocationID>
     <AllocationQuantity>0</AllocationQuantity>
     <ExecutionId>SBALTSE?5.0</ExecutionId>
     <Price>5</Price>
     <GeneralProfile>*</GeneralProfile>
     <Overrides>*</Overrides>
     <Response>*</Response>
     <Quantity>2000</Quantity>
    </ExecutionId>
    <ExecutionId value="SBALOSE?6.0">
     <AllocationBP>0</AllocationBP>
     <AllocationID>*</AllocationID>
     <AllocationQuantity>0</AllocationQuantity>
     <ExecutionId>SBALOSE?6.0</ExecutionId>
     <Price>6</Price>
     <GeneralProfile>*</GeneralProfile>
     <Overrides>*</Overrides>
     <Response>*</Response>
     <Quantity>3000</Quantity>
    </ExecutionId>
   </ExecutionDetailsList>
  </AllocationId>
 </AllocationDetailsList>
</OrderDetails>


In Java, I have a OrderDetails Object with some attributes, AllocationDetails with some attributes and ExecutionDetails with some attributes...

OrderDetails has a list of allocationDetails and allocationDetails has list of executionDetails...


I want to use this XML -- (which comes as a log from client) .. and prepare a java file -- which can automatically populate all the objects and then call other methods...

any ideas on how can I automatically build my object hiearchy based on XML ...

I am okay to use any API's that might have come up doing this-- like hibernate or springs etc..

please help accomplishing this.

regards
0
Comment
Question by:irodov
5 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 34 total points
ID: 17124637
0
 
LVL 10

Assisted Solution

by:mukundha_expert
mukundha_expert earned 33 total points
ID: 17127412
create classes OrderDetails, ExecutionId, AllocationId .... ( use builder pattern )

have readFromXML ( String xmlconfig ) method in all the classes, so that when you pass the Xml it should parse the XMl and populate its members.


so your OrderDetails will be

class OrderDetails
{
  String FirmBook;
String BlockAccMnc;
..
..

List executionDetailsList //list of executionID )
List allocationDetails //

readFromXml () ;

}
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 33 total points
ID: 17128474
>> any ideas on how can I automatically build my object hiearchy based on XML

Try Castor:

http://www.castor.org/ 
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 72
Basic Java Case or If-Else statement... 3 50
runtime exception 2 28
Unhandled exception type Exception 18 31
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question