October 11
InfoPath Development Tip : Use relative path to access node within Node Collection
Use Relative node name within Node collection to access the properties. Do not use absolute path to access the values.
Let us say, you wanted to loop through the node collection and access the value for the child node for each node in the collection.
//Parent Node
XPathNavigator selectNode = tempXPath.SelectSingleNode("/my:ExpenseReport/my:TravelExpenses/my:travelExpense[" + i + "]", NamespaceManager);
//Do not use the below mentioned way(Absolute path) to access the values of the elements
//XPathNavigator tempNode = selectNode.SelectSingleNode("/my:ExpenseReport/my:TravelExpenses/my:travelExpense/my:travelExpenseCategory", NamespaceManager);
//Instead use relative node name like show below, to access the child node
XPathNavigator tempNode = selectNode.SelectSingleNode("my:travelExpenseCategory", NamespaceManager);
Hint: "my:travelExpenseCategory" is the child node under my:travelExpense
Note: If you use absolute path, you will always end up getting the Value from the first element, even though your cursor is at the specified(by variable i) element.
This may be not be a common mistake, nonetheless, I just wanted to share this piece.
Hope that helps!
Thanks
Guru