on 01-07-2009 10:00 AM
Hi,
I have two nodes with same attributes.
I want to compare the data of the two nodes.
How to code this?
thanks,
anumit
Hi,
There are 2 nodes N1 & N2. Both have the same number of attributes.
Now, the datas of the two nodes is same if values of all the attributes are same.
You have to now loop over all the attributes & compare the values.
for (int i=0; i<wdContext.getnodeN1().getAttributes().size(); i++)
{
if ( ! (wdContext.getnodeN1().getElementAt(i).toString().equals(wdContext.getnodeN2().getElementAt(i).toString() ) ) )
return false; // some attribute values do not match
}
return true; //comes here when all the attribute values have matched
Kind Regards,
Nitin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Give a try, by sorting the data in the two nodes with respect to any key attribute and then try to compare the nodes.
Regards
Raghu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anumit,
You can do that in the following way:
1) Let us take the first node as Vn_Node1 and the second as Vn_Node2
2) Have a string variable:
String strVar=null;
3) Have a for loop :
for(int i=0 ; i<wdContext.nodeVn_node().size();i++){
strVar =wdContext.nodeVn_node().getElementAt(i)toString();
if(wdContext.nodeVn_Node2.getElementAt(i).toString().equals(strVar)){
here you can specify the variable that can be set something like dataQuality of integer type, eg,
dqScore+=10;
}
}
Hope it solves your problem.
The solution is applicable only if the structure of the two nodes is exactly same, i.e., the number and name of attributes in the nodes is same.
Regards.
Rajat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
For Example
The 2 nodes say n1 and n2 and attributes say A1 and A2
if you want to compare attribute A1 of n1 with an attribute of A2 of n2 the
use the code below
if(WdContext.currentnoden1.getA1.equals(WdContext.currentnoden2.getA2))
return true;
which menas that if both the values of the 2 nodes are equal then return true;
Regards
Padma N
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
node1.attribute==node2.attribute
Regards,
Sunaina Reddy T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.