cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing node within a node in a context

Former Member
0 Kudos

Hi!

I have Node strucrure like this in my context..

Node (0..n)(singleton="true")

Node1 (0..n)(singleton="true")

Node11 (0..n)(singleton="true")

atrr1

attr2

Can you tell me that how can I access Node11 and its attributes?

Iam having n number of Node1's under each Node and again n number of Node11's under each Node1. I need to access attributes of each Node11. How can i do that??

Thanks,

Archana

Accepted Solutions (1)

Accepted Solutions (1)

monalisa_biswal
Contributor
0 Kudos

Hi Archana,

As u described ur scenario, there are multiple instances of Node1 exist for Node

and Node11 for Node1.So u have to set "singleton" property of child nodes to false.

Otherwise the elements of the relevant node are instantiated for only one element of the parent node.

for(int i=0;i<wdContext.nodeNode().size();i++)

{

wdContext.nodeNode().setLeadSelection(i);

for(int j=0;j<wdContext.nodeNode1().size();j++)

{

wdContext.nodeNode1().setLeadSelection(j);

for(int k=0;k<wdContext.nodeNode11().size();k++)

{

wdContext.nodeNode11().setLeadSelection(k);

wdContext.currentNode11Element.getAttributeValue("attrName");

}

}

}

Hope it helps!

Former Member
0 Kudos

Hi

I havent created my own context nodes.Instead i am dragging the nodes from my Webservice model into my component controller and there i am not able to change its properties. I cant change singleton property to false as you suggested.

Can you suggested me some other way..

Thanks,

Archana

Former Member
0 Kudos

Incase of webService model, refer to this post

Regards, Anilkumar

Former Member
0 Kudos

Thanks for the suggestion.

It helped me to solve my problem to some extent..

Thanks,

Archana

Answers (6)

Answers (6)

monalisa_biswal
Contributor
0 Kudos

Hi Archana,

Since its singleton property has been set to true u dont need to iterate on parent node.U can directly iterate child node

if(wdContext.nodeNode11()!=null)

{

for(int k=0;k<wdContext.nodeNode11().size();k++)

{

wdContext.nodeNode11().setLeadSelection(k);

wdContext.currentNode11Element.getAttributeValue("attrName");

}

}

Former Member
0 Kudos

Hi,

Try this,

String att1 = null, att2 = null;

for(int i =0; i<wdContext.nodeNode().size; i++){

for(int j = 0; j<wdContext.nodeNode().nodeNode1().size; j++){

for(int k = 0; k<wdContext.nodeNode().nodeNode11().size; k++){

att1 = wdContext.nodeNode().nodeNode1().nodeNode11().getNode11ElementAt(k).getAtt1();

att2 = wdContext.nodeNode().nodeNode1().nodeNode11().getNode11ElementAt(k).getAtt2();

}

}

}

Former Member
0 Kudos

Hi,

The proposed cardinality for parent node should be 1:n & for Child nodes it should be 0:1.

u can access the child node attributes like this.

String one =WdContext.current<childNode>Element()..getAttr1();

String two =WdContext.current<childNode>Element()..getAttr2();

Thanks,

Lohi.

lajitha_menon
Contributor
0 Kudos

Hi,

You can directly access a child node like node11 from the context using wdContext.currentnode11Element().getAttr1() provided node11 has atleast 1 line.All the parent contexts must be initialised as well(here you have to do explicity by addelement() as you have all cardinalities as 0..n)

To access each element , you can put it in a for loop.

Regards,

LM

roberto_tagliento
Active Contributor
0 Kudos

wdContext.currentNodeElement().currentNode1Element().currentNode11Element().getAtrr1();

You can surf the context:

wdContext.nodeNode().movefirst();
do{
   
   wdContext.currentNodeElement().nodeNode1().movefirst();
   do{
   
      wdContext.currentNodeElement().currentNode1Element().nodeNode11().movefirst();
   do{
   
   wdContext.currentNodeElement().currentNode1Element().currentNode11Element().getAtrr1();



    } while ( wdContext.currentNodeElement().currentNode1Element().nodeNode11() );


    } while ( wdContext.currentNodeElement().nodeNode1().moveNext() );


} while ( wdContext.nodeNode().moveNext() );

Message was edited by:

Roberto Tagliento

roberto_tagliento
Active Contributor
0 Kudos

It´s better use variable for get the node and nope somthing long like this:

wdContext.currentNodeElement().currentNode1Element().currentNode11Element().getAtrr1();

Former Member
0 Kudos

Hi Archana,

Select the cardinality as (1..1) for the root node and for the remaing nodes keep the same(0..n). I mean if your node11 is in node1 and node1 is in node you have to make the cardinality (1..1) for node, and for the remaing node node1 and for node11 keep the same cardinality (0..n).

Regards

Suresh