Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default Translating an XML with the DOM ParserAPI

    Hello experts,
    Here is what i am trying to achieve, I have a source XML which i need to translate it to a target xml with a different format/ structure as shown below:
    Now the plan is to do this using Java, I do know of 2 APIs SAX and DOM,

    I'd like to implement this using a DOM parser(eazier)
    I would appreciate any guidance from anyone who's got some expertise on this:

    Requirement:
    Source XML Structure:
    -The "summary" has details about a manager.
    -A manager may either have a Distributor directory under him - If he has a distributor under him , that distributor will always have a seller assigned to him.
    - A manager can have a Seller directly assigned under him.

    Java Code:
    <RequestBody>
    	<Summary>
    		<ManagerName>Keith</ManagerName>
    		<ManagerID>K09090</ManagerID>
    		<Distributer>Raymond</Distributer>
    		<DistributerID>R87877</DistributerID>
    		<Seller>Alex</Seller>
    		<SellerID>A9876</SellerID>
    	</Summary>
    	<Summary>
    		<ManagerName>Keith</ManagerName>
    		<ManagerID>K09090</ManagerID>
    		<Distributer>Robert</Distributer>
    		<DistributerID>R11111</DistributerID>
    		<Seller>Blake</Seller>
    		<SellerID>B09976</SellerID>
    	</Summary>
    	<Summary>
    		<ManagerName>Keith</ManagerName>
    		<ManagerID>K09090</ManagerID>
    		<Seller>Marie</Seller>
    		<SellerID>M87656</SellerID>
    	</Summary>
    	<Summary>
    		<ManagerName>John</ManagerName>
    		<ManagerID>J97654</ManagerID>
    		<Seller>Charlie</Seller>
    		<SellerID>C98765</SellerID>
    	</Summary>
    	<Summary>
    		<ManagerName>John</ManagerName>
    		<ManagerID>J97654</ManagerID>
    		<Seller>Drew</Seller>
    		<SellerID>D98455</SellerID>
    	</Summary>
    </RequestBody>

    And here is the target XML structure I need to Map to:

    Java Code:
    <ResponseBody>
    	<ManagerEntity>
    		<ManagerName>Keith</ManagerName>
    		<ManagerID>K09090</ManagerID>
    		<Distributer>
    			<DistributerName>Raymond</DistributerName>
    			<DistributerID>R87877</DistributerID>
    			<Seller>
    				<SellerName>Alex</SellerName>
    				<SellerID>A9876</SellerID>
    			</Seller>
    		</Distributer>
    		<Distributer>
    			<DistributerName>Robert</DistributerName>
    			<DistributerID>R11111</DistributerID>
    			<Seller>
    				<SellerName>Blake</SellerName>
    				<SellerID>B09976</SellerID>
    			</Seller>
    		</Distributer>
    		<Seller>
    			<SellerName>Marie</SellerName>
    			<SellerID>M87656</SellerID>
    		</Seller>
    	</ManagerEntity>
    	<ManagerEntity>
    		<ManagerName>John</ManagerName>
    		<ManagerID>J97654</ManagerID>
    		<Seller>
    			<SellerName>Charlie</SellerName>
    			<SellerID>C98765</SellerID>
    		</Seller>
    		<Seller>
    			<SellerName>Drew</SellerName>
    			<SellerID>D98455</SellerID>
    		</Seller>
    	</ManagerEntity>
    </ResponseBody>
    I would really appreciate any leads or any help on this as i haven't implemented this.

    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    XSLT, as an immediate answer, for which there are scads of examples around on how to set up Java to transform one lot of XML into another using a stylesheet. Take a look at the Sun tutorials, since I would expect there to be one on there.

Similar Threads

  1. Translating Pascal into java
    By willemjav in forum Advanced Java
    Replies: 120
    Last Post: 08-15-2008, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •