Beginning XML Databases (Wrox Beginning Guides)
| ||
| ||
|
1. | What is the difference between the following two XPath expressions?
/root/nodeA/nodeB and:
nodeA/nodeB | |
2. | Which of the following statements is the best answer for the following XPath expression:
//country/../@name
| |
3. | What is the best answer for what this XPath expression will find?
demographics/region/country/city[last()-1]"/>
| |
4. | What will this XPath expression find?
demographics/region/country[@*]
| |
5. | Which of the following are possible answers, with respect to this XPath expression?
//child::collectionofthings/../parentofcollectionofthings/bigthings/attribute::*
| |
Answers
1. | Exercise 1 solution The first expression is an absolute path and the second is a relative path. An absolute path scans from the specified node, generally the root. A relative path scans from the current path. The current path is the current point to where any processing has scanned to, within an XML document. |
2. | Exercise 2 solution e. None of the above. The expression //country/../@name searches for country nodes anywhere in the document. Then the two dots move upward to the parent node (that could be a region node), where the parent node has an attribute called name . |
3. | Exercise 3 solution d. The second last city for every country is the best answer because we are not specifically sure of the structure of the XML document. Assuming the demographics node is the root node, the XPath expression finds all cities, within countries, within regions. The predicate applied to the city finds the last city in the collection of cities, less 1 (the seconds last city). |
4. | Exercise 4 solution d. All countries with at least 1 attribute. The entire contents will not be found because [@*] is a predicate, and any data outside of the path /demographics/region/country will be missed. Countries beginning with the letter A is completely nonsensical because nothing in the expression gets anywhere near specifying that particular restriction. The predicate [@*] implies all attributes within the country element, and thus at least 1 applies in this case. |
5. | Exercise 5 solution a. Get all attributes of a node called bigthings is a good answer because the expression includes bigthings/attribute::* . Answer b is incorrect because parentofcollectionofthings is actually a sibling of collectionofthings (child finds the child of the former) there is no parent node in this picture at all. Answer c is incorrect because it contradicts the first two, and its simply wrong. The same applies to d. Answer e (Get zip!) implies get nothing. Actually this could be a good answer as well because you dont know the content of the XML document anyway. |
| ||
| ||
|