on 02-23-2008 12:53 AM
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"
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.