(: CSC 468 :) (: Winter 2010 :) (: Project Stage 3 :) (: test queries for "unit-testing" your XPLite implementation (: note: not all features can be unit-tested. (: For example, implementations of built-in functions (: can be unit-tested only if we validate at least one non-trivial (: axis (: So, really, this is a test script for differential testing of your XPLite (: implementation (: Test individual axes (: 1. get the root node RETURN document("Nutrition")/self::node() RETURN document("Franc")/self::node() (: 2. get all child nodes of the root RETURN document("Nutrition")/child::node() RETURN document("Franc")/child::node() (:3. get all grandchildren of the root RETURN document("Franc")/child::node()/child::node() (:4. check the parent axis. Should retrieve the same answer as query 2. RETURN document("Nutrition")/child::node()/child::node()/parent::node() RETURN document("Franc")/child::node()/child::node()/parent::node() (:5. Name Node Test. Retrieve amount RETURN document("Franc")/child::amount (:6. "*" wildcard Retrieve children using the "*" wildcard RETURN document("Franc")/child::amount/child::* (:7. descendant axis (+ name node test) RETURN document("Franc")/descendant::unit RETURN document("WiiGames")/descendant::Title (:8. find ancestors of the year element (mint, origin, currency) RETURN document("Franc")/descendant::year/ancestor::* (:9. one more ancestor test: returns just the origin element RETURN document("Franc")/descendant::year/ancestor::origin (:10. Preceding. Should return country, form and paper. RETURN document("Franc")/descendant::mint/preceding::node() (:11. Following. Should return amount, denom, unit and valid. RETURN document("Franc")/descendant::year/following::node() (:12. text() node test. Returns paper, country, city, year, denom, unit and valid. (:(: note, that coin is returned (although it does not have text content. (:(: this is because it IS a leaf node. RETURN document("Franc")/descendant::text() (:13. Predicates. a simple XPath expression. Find all elements that have children. (: Returns form, origin, mint, amount - note, currency is not returned, because (: we used descendant axis in the query. RETURN document("Franc")/descendant::node()[child::node()] (:14. Predicates. XPath expression. Find a node that has year as a grandchild. RETURN document("Franc")/child::*[child::*/child::year] (:15. Predicates. functions. position(). equality. First child of the root (: Isaac Murphy's Last Ride for horses (: note, it also tests equality RETURN document("Horses")/child::*[position()=1] RETURN document("Nutrition")/child::*[position()=1] (:16. Predicates. functions. position(). last(). equality. Last child of the root (: Mo for Horses (#79) java XpathPlus RETURN document("Horses")/child::*[position() = last()] (:17. Predicates. functions. position(). last(). equality. Last child of the root (: Mo for Horses (#79) java XpathPlus RETURN document("Horses")/child::*[position() = last()] java XpathPlus RETURN document("WiiGames")/child::*[position() = last()] (:18. Predicates. functions. position(). Middle of the pack (: Not so plain Joe java XpathPlus RETURN document("Horses")/child::*[position() = 20] (:19. Predicates. functions. string() with no parameter. equality. (: Find the element whose content is "Franc" RETURN document("Franc")/descendant::*[string() = "Franc"] (:20. Attribute axis RETURN document("Nutrition")/descendant::nutrition/attribute::name (:21. Attribute axis. Predicates. string() on attribute nodes. RETURN document("Nutrition")/descendant::nutrition/attribute::name[string()="MisoSoup"] (:22. Predicates. functions. string() with a parameter. (: Horse created by an artist with the last name Slone (#20) RETURN document("Horses")/descendant::horse[string(descendant::artist/child::last)="Slone"] (: All Seinfeld episodes that earned a grade of "A" RETURN document("Seinfeld")/descendant::episode[string(descendant::grade) = "A"] (:23. Predicates. functions. count(). equality. Find elements with two children. RETURN document("Franc")/descendant::*[count(child::*)= 2] (:24. predicates, functions, not() (: finds all XML nodes with no children RETURN document("Franc")/descendant::node()[not(child::*)] (:25. predicates, functions, not(), true(), boolean equality (: finds all XML nodes with no children RETURN document("Franc")/descendant::node[not(child::*) = true()] (:26. predicates, functions, not(), false(), boolean equality (: all the nodes that DO have children RETURN document("Franc")/descendant::node[not(child::*) = false()] (:27. predicates, functions, position, operations, equality RETURN document("Horses")/descendant::horse[position() = 3] (:28. predicates, functions, position, operations, inequality RETURN document("Nutrition")/descendant::nutrition[position() <> 3] (:29. predicates, functions, position, operations, less than RETURN document("Horses")/descendant::horse[position() < 3] (:30. predicates, functions, position, operations, less than or equal to RETURN document("Horses")/descendant::horse[position() <= 3] (:31. predicates, functions, position, operations, greater than RETURN document("Horses")/descendant::[position() > 77] (:32. predicates, functions, position, operations, greater than or equal to RETURN document("Horses")/descendant::horse[position() >= 77]/child::title (: 33. predicates. functions. contains() (: find all episodes that mention "girlfriend" in synopsis RETURN document("Seinfeld")/descendant::episode[contains(child::synopsis, "girlfriend")] RETURN document("Seinfeld")/descendant::episode[contains(child::synopsis, "girlfriend")]/child::title (: find all nodes that contain the text "Seinfeld" RETURN document("Seinfeld")/descendant::node()[contains(self::node(), "Seinfeld")] (:33. predicates, multiple nesting RETURN document("WiiGames")/child::node()[self::node()[self::node()[self::node()[self::node()[self::title]]]]] (:34. predicates, multiple predicates (: returns horses #3 and #4 java XpathPlus RETURN document("Horses")/descendant::horse[self::horse][position() < 5][position() > 2][not(parent::author)] (:35. attribute axis: all attributes RETURN document("Nutrition")/child::nutrition/attribute::node() (:36. attribute axis, node name test RETURN document("Nutrition")/child:nutrition/attribute::brand RETURN document("Nutrition")/child:nutrition/attribute::name (:37. attribute axis, string() function RETURN document("Nutrition")/child::nutrition/attribute::name[string()="Super Fruit Punch"] (:38. attribute axis, contains() function RETURN document("Nutrition")/child::nutrition/attribute::name[contains(self::node(), "Fruit")] (:39. attribute axis, parent axis. RETURN document("Nutrition")/child::nutrition/descendant::vitamin/attribute::node()/parent::*[string()="Iron"] (:40. attribute axis RETURN document("Nutrition")/descendant::vitamin[attribute::percentage[string()="10"] (:41. attribute axis (: nodes with no attributes java XpathPlus RETURN document("Nutrition")/descendant::nutrition[position()=1]/descendant::node()[not(attribute::node())] (: (: AND WE ARE DONE! (: