I have the following predicate:
var predicate = "$record.TopMerchants.Record[*]";
var nodeitems = $data.resolveNodes(predicate);
which searches an XML structure similar to the following:
<TopMerchants>
<Record>
<Country>United Kingdom</Country>
<X1>testing</X1>
<X2>testing again</X2>
</Record>
<Record>
<Country>United Kingdom</Country>
<X1>testing</X1>
<X2>testing again</X2>
</Record>
<Record>
<Country>United States</Country>
<X1>testing</X1>
<X2>testing again</X2>
</Record>
</TopMerchants>
This works fine in retrieving all of the records under the TopMerchants node, however what I really want is to be able to bring back records that have a specific country but I am not sure how this is done in the predicate, can anyone shed any light as to how you would achieve this??
Solved! Go to Solution.
Views
Replies
Total Likes
You sure can use predicates to search almost anything. In your case
xfa.record.resolveNodes('TopMerchants.Record.[Country=="United Kingdom"]')
The period denotes the start of the predicate. It returns all the Record's that meet the condition between [] for FormCalc and () for JavaScript.
I personally tend to use the applyXPath method just because I'm use to using XPath expressions but it's only a personal preference (not sure which one is faster):
XMLData.applyXPath(xfa.data,"TopMerchants/Record[Country='United Kingdom']")
It looks more complicated but on intense searches with multiple parameters I find it easier. In your case though I'd use the predicates.
Kyle
Views
Replies
Total Likes
You are working with XML format, so this is all nodes
to be able to access Country from Record, I don't think you can do Record[*] (not sure)
to my knowledge, to be able to access Country you would have to write something like so
for (var i = 0; i < predicate.nodes.length; i++){
if (predicate.nodes.item(i).value.text.value == "Any country"){
//Code here
}
}
Because you have already written resolveNodes() i am not sure if you can do this but try this or the other above
for (var i = 0; i < nodeItems.nodes.length; i++){
//Code here
}
Views
Replies
Total Likes
Thanks Robert, I should have mentioned that I am already performing a for loop as above, however this seems like an unecessary and potentially processor intensive step especially in that there might 100's of records returned that I don't necessarily need as they are not related to the country I am showing, so I was wondering if there was a way of doing this at predicate level so that only the nodes with a matching country sub-item are returned. This of course may not be possible but it would be good to know for sure.
Views
Replies
Total Likes
for 100 record it should not be really long to process...
Even for 1000 it would not be long to process since its only a loop and not a recursive method
I've already made a recursive method that loops over all the pdf document for each nodes which is over 1000's of nodes
and it doesn't take too long to get through all the nodes...
the loop i provided is the best option you have in this case
Views
Replies
Total Likes
You sure can use predicates to search almost anything. In your case
xfa.record.resolveNodes('TopMerchants.Record.[Country=="United Kingdom"]')
The period denotes the start of the predicate. It returns all the Record's that meet the condition between [] for FormCalc and () for JavaScript.
I personally tend to use the applyXPath method just because I'm use to using XPath expressions but it's only a personal preference (not sure which one is faster):
XMLData.applyXPath(xfa.data,"TopMerchants/Record[Country='United Kingdom']")
It looks more complicated but on intense searches with multiple parameters I find it easier. In your case though I'd use the predicates.
Kyle
Views
Replies
Total Likes
Hi Kyle,
It's some time since you posted this answer, however I am now running into the situation where I need to specify multiple parameters, are you able to provide me with a couple of examples of the applyXPath method doing a query using multiple parameters?
Thanks in advance.
Graham
Views
Replies
Total Likes
Maybe instead, if you want to send me an example of what you require I can try to send you a predicate that will work for you.
Kyle
Views
Replies
Total Likes
Thanks for the reply Kyle, however since the post I have now managed to work it out, for the benefit of others see an example below:
var nodeitems = xfa.record.resolveNodes('datasourcename.Record[Criteria1=="Test" and Criteria2=="Test" and Criteria3=="Test"]');
Views
Replies
Total Likes