Be aware of a weird behavior in the Fixlet Debugger - when you run multiple queries in one QNA tab, the time seems to “add up” from the bottom to the top.
I.e. the time listed for a query, is the sum of that query’s time and every query that falls below it on the page. I regard it as a bug, but I’ve heard it argued that it’s expected behavior.
In any case, when comparing times of queries be sure to have each query by itself on separate tabs.
For the XML query, its possible to express the whole thing as an XPath expression, but I found the time difference negligible (42 ms for pure XPath vs 47 ms for your original query on my system):
q: node values of xpaths "/students/item/career_aspiration[text()='Lawyer']/../email/text()" of (xml documents of file "C:\temp\student-scores.xml")
<snip>
T: 42.764 ms
q: node values of xpaths "email/text()" of parent nodes of parent nodes of xpaths "/students/item/career_aspiration/text()" whose (node value of it = "Lawyer") of (xml documents of file "C:\temp\student-scores.xml")
<snip>
T: 47.115 ms
I found a couple of other ways to express the XPath after I started writing this, but they all had similar evaluation times; I’m posting them here just in case they’re helpful refs
Original:
q: node values of xpaths "/students/item/career_aspiration[text()='Lawyer']/../email/text()" of (xml documents of file "C:\temp\student-scores.xml")
Explanation: Start at studens/item/career_aspiration with a text value of “Lawyer”, then move up one node (to ‘item’) and then down to ‘email’ and return the text() value.
q: node values of xpaths "/students/item/email[../career_aspiration/text()='Lawyer']/text()" of (xml documents of file "C:\temp\student-scores.xml")
Explanation: Find the stuends/item/email node, where the parent node has a career_aspiration node with a text() value of ‘Lawyer’; from that email node return the text() value.
q: node values of xpaths "/students/item[career_aspiration/text()='Lawyer']/email/text()" of (xml documents of file "C:\temp\student-scores.xml")
Explanation: Find the item nodes which contain child node of ‘career_aspiration’ with a text() value of ‘Lawyer’; from that item node, find the email child node and return the text() value of it.
This last form I think is the cleanest but it’s all a matter of preference and different queries can make more sense in different situations.