wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Merging repeted elements in XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Merging repeted elements in XML" Watch "Merging repeted elements in XML" New topic
Author

Merging repeted elements in XML

Manoj Jena
Greenhorn

Joined: Aug 31, 2011
Posts: 3
Hi,
I have an xml file with the following content.
<abc>
<a>
<b/>
</a>
<c>
<d/>
</c>
</abc>
<abc>
<a>
<b/>
</a>
<e>
<f/>
<g>
<h/>
</g>
</e>
<i/>
</abc>


I want to merge these 2 in to one, like the below.

<abc>
<a>
<b/>
</a>
<c>
<d/>
</c>

<e>
<f/>
<g>
<h/>
</g>
</e>
<i/>
</abc>

Appreciate any help on this and can I do this using DOM parser ?

Thanks,
Manoj
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your first step would be to figure out how to identify "repeated" elements. Once you have done that, then yes, you should be able to do it with DOM programming.
Manoj Jena
Greenhorn

Joined: Aug 31, 2011
Posts: 3
Hi,

I don't have a specific pattern and the xml provided is only part of the huge XML that I have.

Thanks,
MJ
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Okay. So your problem is solved then?
Manoj Jena
Greenhorn

Joined: Aug 31, 2011
Posts: 3
Not yet looking for a feasible solution on this. Appreciate any sample code on this.

Thanks,
MJ
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You are asking for code? That means you must have completed your requirements, which include a description of how to identify duplicate elements.

But if you think about it, we don't know what you decided there. So asking for code to do that is rather useless. Why don't you post the rules for identifying duplicate elements, and we can discuss that? Don't expect anybody to write the code for you, though, that isn't how this forum works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Merging repeted elements in XML
 
Similar Threads
The Conditional Operator ?:
New Mock Exam questions...
visualizing hierarchy structure
Logic with java code
conditional operater?