There are cases where a user would want to evaluate an XML structure to determine the total number of nested XML elements or evaluate to see if a nested XML element exists.
In this example, we will use the following XML structure and assume that it is stored within a user defined attribute (UDA) named “FoodUDA”.
<Food>Solution# 1: In order to find the total the XData.count(xpath) method can be used on the XML structure. This is a method, given an xpath, would return the number of child elements found with a given name.
If there are NO children with that name, it returns 0
If there is one child with that name, it returns 1
If there are 5 children with that name, it returns 5
For example, based on the example above, xdata.count(“Food/foodData/Fruit/fruitType”) would return 2.
Solution#2: Another solution that is available is to use the XData.getValue in conjunction with the javascript dot notation to achieve the loop exist condition
if (uda.FoodUDA.Food.foodData.foodRecords.Fruit[2].getValue(“fruitType”) != null) {
uda.NumOfTaskRecords = 2;
However, this is not the same as above and will not work:
if(uda.FoodUDA.Food.foodData.foodRecords.getValue(“Fruit[2]”!=null){
uda.NumOfTaskRecords = 2;
Author: Marc Bui
Attachment: How_to_Use_Model_API_to_Evaluate_Existence_of_XML_Element.zip