Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merging repeted elements in XML

 
Manoj Jena
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20716
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20716
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So your problem is solved then?
 
Manoj Jena
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not yet looking for a feasible solution on this. Appreciate any sample code on this.

Thanks,
MJ
 
Paul Clapham
Sheriff
Pie
Posts: 20716
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic