Skip to Content
0
Former Member
Apr 20, 2009 at 04:40 PM

Mapping issue - Remove Duplicates

23 Views

Hello,

I want to remove the duplicate nodes. Below is the issue:

Input Structure:

MainNode 0..n

--SubNode 0..n

-


key

-


Val

Output Structure:

MainNode 0..n

--Subnode 0..n

-


key

-


Val

Now the example input:

<MainNode>

<subnode>

<key> 1001 </key>

<val< 1 </Val>

</Subnode>

<subnode>

<key> 1002 </key>

<val> 2 </val>

</subnode>

<subnode>

<key> 1001 </key>

<val> 1 </val>

</subnode>

Output should be:

<MainNode>

<Subnode>

<key> 1001 </key>

<val> 1 </val>

</subnode>

<subnode>

<key> 1002 </key>

<val> 2 </val>

</subnode>

i.e., it should remove the duplicate keys.

I tried as below, but doesnot work:

key --> removeContext --> Merge userdefinded function -->Subnode

Merge:

public void merge(String[] key, ResultList result, Container container) {

HashSet hs = new HashSet();

for(int i = 0; i < a.length; i++) {

hs.add(a<i>);

}

Iterator it = hs.iterator();

while(it.hasNext()) {

String val = it.next().toString();

result.addValue(val);

result.addContextChange();

}

}

Any other solution?