cancel
Showing results for 
Search instead for 
Did you mean: 

add several elements to a node

Former Member
0 Kudos

Hello experts,

I'm trying to add several elements to a node I have, the node cardinality is 0..n and the data I'm trying to pass comes from a hashtable, this is the code I have:


ICifrasControlElement cifras = wdThis.wdGetContext().createCifrasControlElement();
for(;enum.hasMoreElements();){
							
String key = (String)enum.nextElement();
String value = (String)res.get(key);				

cifras.setConcepto(key);
cifras.setValor(value);
wdContext.nodeCifrasControl().addElement(cifras);
}

I'm getting this exception:"cannot bind or add element, because it is already bound to a node"

Accepted Solutions (1)

Accepted Solutions (1)

nikhil_bose
Active Contributor
0 Kudos

ICifrasControlElement cifras = null
for(;enum.hasMoreElements();){

cifras = wdThis.wdGetContext().createCifrasControlElement();
// creating context for each enum.elements

..
..
}

make cifras node cardinality to 1..n

regards,

nikhil

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Change your code as follows


for(;enum.hasMoreElements();){
ICifrasControlElement cifras = wdThis.wdGetContext().createCifrasControlElement();
						
String key = (String)enum.nextElement();
String value = (String)res.get(key);				
 
cifras.setConcepto(key);
cifras.setValor(value);
wdContext.nodeCifrasControl().addElement(cifras);
}

Regards

Ayyapparaj

ThatSAPGuy
Advisor
Advisor
0 Kudos

Jesus-

Your problem is you have created only one element and you are adding the same reference in the loop. Change your code as follows:


for(;enum.hasMoreElements();){
							
String key = (String)enum.nextElement();
String value = (String)res.get(key);				

ICifrasControlElement cifras = wdThis.wdGetContext().createCifrasControlElement();
cifras.setConcepto(key);
cifras.setValor(value);
wdContext.nodeCifrasControl().addElement(cifras);
}

Cheers-

Atul

sridhar_k2
Active Contributor
0 Kudos

Use this code, it work for you.

You were trying to add the same element once again to the node, so it is throwing exception.

ICifrasControlElement cifras = null;

for(;enum.hasMoreElements();){

cifras = wdThis.wdGetContext().createCifrasControlElement();

String key = (String)enum.nextElement();

String value = (String)res.get(key);

cifras.setConcepto(key);

cifras.setValor(value);

wdContext.nodeCifrasControl().addElement(cifras);

}

Regards,

Sridhar

Former Member
0 Kudos

Hello Sridhar, thank you for your answer, I had already done that.. still get the exception...

Node(FOVSITYF_CONTA_comp.CifrasControl): cannot bind or add element, because it is already bound to a node

Any other ideas? Thanks in advance..

Former Member
0 Kudos

The first element is being added, but when the second element comes is when the exception is reaised.. thanx!