cancel
Showing results for 
Search instead for 
Did you mean: 

Node traverse

Former Member
0 Kudos

Hi ,

As per my understanding, node is nothing but a matrix kind of architechure. having multiple elements (fields) in that node.

When u assign this node to a table it shows number of rows available in that node.

My requirement is that I want to traverse each value of the node using loop, (Example 2 nd row 3rd value, 3 rd row and 2 nd value)

How can i achive this using loops , could u help me?

Regards,

Jyothi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Say if you have Node1(value node)

name(first value attribute for Node1)

ID(second value attribute for Node1)

If you bind node one to your table it will have Name and ID fields.

If you want to get all the values like 1st row and second row, use the code below.

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

{

wdcontext.nodeNode1.getNode1elementat(i).getname();//gives names at all index

wdcontext.nodeNode1.getNode1elementat(i).getID();//gives corresponding ID at all index

}

Former Member
0 Kudos

Hi prasanthi reddy ,

I don't find the method you have given " .getID()".

for(int j=0;j<wdContext.nodeIt_Out().size();j++)
     	 {
     	 	wdContext.nodeIt_Out().getIt_OutElementAt(j).getDeparture_Airp();.
                           wdContext.nodeIt_Out().getIt_OutElementAt(j).----------
     	 	
     	 }

Regards,

Jyothi.

pravesh_verma
Active Contributor
0 Kudos

Hi Jyothi,

See the concept of accessing the nodes etc is very simple. Compare the node with a simple Database table.

Like you have database table similarly there is a node.

Like we have columns in the DB table we have attributes in the node.

As we go on creatign the elements of the node, similarly we create the rows in the tabel and set the values.

I hope this is clear.

Now regaring the get and set values. The code which Prasanthi has given is according to what attributes he has in his nodes. you may not have those attributes thats why you didnt get the getID().

You always have to get the values of the attributes by the get funtions. So you may have the node with you lets say It_Out, which you have given so you will get the corresponding get__() methods for only those attributes which are present under this nodeIt_Out.

I hope this clears the issue.

Now lets come back to your initial requirement:

>>My requirement is that I want to traverse each value of the node using loop, (Example 2 nd row 3rd value, 3 rd row and 2 nd value)

Do like this:


IwdNodeElement ele = null;
String Departure = null;
for(int j=0;j<wdContext.nodeIt_Out().size();j++)
     	 {
     	 	ele = wdContext.nodeIt_Out().getIt_OutElementAt(j);
                                 Departure  = ele.getDeparture_Airp();
                                // Please note that this will now give you the values of the departure according to the loop counter. 
                               // Lets say you have 4 elements in th your node then this loop will run 4 times and value of Departure can be get using the code above
     	 }

I hope this solves your issue!

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi Pravesh Verma

Yes , Now it is clear. I was under impression that we have such a method called getID() .

My requirement is not yet fulfiled here. As you said we can get the values of attribues by using getAttribuename(), But ! I want to travese throught index of one row( not the names) since I am using it in the loop.

Hope this is clear.

Regards,

Jyothi.

pravesh_verma
Active Contributor
0 Kudos

Hi,

I can understand that you are in the loop however there is no direct way to access the attributes by giving there index. However you need to do it some other way. Get the list of the attributes in a seperate list then iterate the list to get the attribute.Try this code:


List atrList = wdContext.nodePerson().getNodeInfo().getAttributes();

Then iterate over this List to get values.


IWDNodeElement ele = null;
String Departure = null;
int size = 0;
if(atrList!=null){
size = atrList.size();
}
String attrName = null;

for(int j=0;j<wdContext.nodeIt_Out().size();j++)
     	 {
     	 	ele = wdContext.nodeIt_Out().getIt_OutElementAt(j);
                                for (int i = 0; i < size; i++) {
		attrName = ((IWDAttributeInfo)atrList.get(i)).getName();	
                                ele.getAttributeValue(attributeName); // this statement will conatin the values of the attributes.                             	
	                 }

                   }

I hope this solves the issue.

Thanks and Regards,

Pravesh

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I just have given name and ID as value attributes for example. you will get whaever attributes you have under your node.

Thanks.