cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing an attribute in a node

Former Member
0 Kudos

Hi,

I created a node Person. It contains two attributes FName and LName.

In order to access these attributes, I am using

wdContext.currentPersonElement.getFName();

wdContext.currentPersonElement.getLName();

But in a book I saw the followind code to access the attribute

IPersonNode node = wdContext.nodePeople();

IPersonElement ele = node.currentPersonElement();

String fname = ele.getFName();

String fname = ele.getLName();

What is the difference between these two. In which scenarios we use the first one and in which scenarios we use the second one?

Regards

V. Suresh Kumar

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

The wdContext.current<Node>Element() methods are shortcuts for accessing the "current" element in a node. The current element is defined by following the lead selection from the context root down to the node in the context hierarchy.

If the node is a non-singleton child node of some parent node "Parent", then you probably don't want to follow this lead-selection path but access the node that belongs to some other (not lead-selected) element of "Parent".

Armin

Former Member
0 Kudos

Hi,

There is a mistake in my code

IPersonNode node = wdContext.nodePeople();

IPersonElement ele = node.currentPersonElement();

String fname = ele.getFName();

String fname = ele.getLName();

I had given IPersonNode node = wdContext.nodePeople() previously. Its not People, it is person.

The updated code is as below:

IPersonNode node = wdContext.nodePerson();

IPersonElement ele = node.currentPersonElement();

String fname = ele.getFName();

String fname = ele.getLName();

Regards

V. Suresh Kumar

Former Member
0 Kudos

Hi,

IPersonNode node = wdContext.nodePeople();

IPersonElement ele = node.currentPersonElement();

String fname = ele.getFName();

String fname = ele.getLName();

If you closely look at the above code it looks like a recursive node is the context structure.

NodePeople-> NodePerson

IPersonNode node = wdContext.nodePeople(); will have error

Regards

Ayyapparaj

Former Member
0 Kudos

There's no difference between them... you can use both and obtain the same result! it is just a point of view unless you are working with dynamic contexts or using the singleton property set to true (in which case you should be careful or you won't get the information stored)

Former Member
0 Kudos

Hi,

Both are same. If you look clearly, they resolve to same syntax. Second one is more lengthier. That is the only difference. It is like this example.

Apple a = new Apple();
a.setName("Apple");

is same as

new Apple().setName("Apple");

Regards,

Harini S

Former Member
0 Kudos

Both are going to return the same in the current scenario.We make use of the

IPersonNode node = wdContext.nodePeople();

IPersonElement ele = node.currentPersonElement();

We make use of the element if e have to bind some 'n' number of records to a node.

where as the

wdContext.currentPersonElement.getFName();

wdContext.currentPersonElement.getLName();

is going to hold the current values of the attributes.(i.e, a single value)

If make use of element we can loop till the size of the node and add 'n' number of records to the node.

Former Member
0 Kudos

Hi,

Both will return the same values() ie Fname and Lname.

We can use the Second set of statement as single one as first..

or

wdContext.node<NodeName>().current<Node>Element().get<Field>();

Regards

LakshmiNarayana

Former Member
0 Kudos

Hi,

What is your node Structure?Do you have people node directly under the context and person node under the people node?

If so then both the cases which you have mentioned are same.

Both returns the current lead selected element under the people node.If no element is selected then it returns null.