0

Is it somehow possible to filter all duplicate elements on the same level in an org.dom4j.Document object in Java?

For example

<parent>
    <child><value>1</value></child>
    <child><value>1</value></child>
    <child><value>3</value></child>
</parent>

should lead to

<parent>
    <child><value>1</value></child>
    <child><value>3</value></child>
</parent>

Is there already a built in functionality for this? Or maybe a library that one could use?

Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109
  • Have you looked at Node.selectElements method? There is an optional removeDuplicates flag. Maybe this will help: http://akmishra30.blogspot.co.at/2014/01/dom4j-remove-duplicate-xml-elements.html But if you want to directly manipulate the structure of the document and not to work with lists, I'm afraid you might have to write your own implementation. – JanM Sep 18 '14 at 10:07

1 Answers1

0

No functionality for this.

The org.w3c.dom.Node interface provides the removeChild method Code example

xmlDoc=loadXMLDoc("books.xml");

y=xmlDoc.getElementsByTagName("book")[0];

xmlDoc.documentElement.removeChild(y)

Or use XSLT

- Documentation : http://docs.oracle.com/cd/B19306_01/appdev.102/b14252/adx_j_xslt.htm
- Example : http://stackoverflow.com/a/10914512/4017037
stacky
  • 800
  • 6
  • 18