commit cf9470e6d095678c4cda1b84ed388fba928cc5c0 Author: Wojciech Mizia Date: Mon Jun 3 15:03:25 2024 +0200 add template files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e99bc4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties + +.idea + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e41b12 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# XPATH-repository-tasks: + + +## Complete the XPathTasks.xml file that is located in src/main/resources/xpath with the answers to the following exercises: +1. Take XML with books and calculate number of all books available. +2. Take XML with books and return first, third and last book from collection +3. Take XML with books and return book with id = 7 from collection +4. Take XML with books and return all books from year 2018 +5. Take XML with books and return all books which was released between 1990 and 1995 +6. Take XML with books and return book with title starting with word Harry +7. Take XML with books and return book witch contains word "Law" in the title +8. Take XML with books and return all attributes that are named id use // operator +9. Take XML with books and return all attributes that are named id don't use // operator +10. Take XML with books and return all node names in document +11. Take XML with books and return book written by authors which are still alive +12. Take XML with readers and sum age of all readers +13. Take XML with readers and return age node name without namespace for book with id = 7 +14. Take XML with readers and return lastname node name with namespace for book with id = 4 +15. Take XML with readers and return namespace for reader with id = 2 +16. Take XML with readers and return first name and last name for each reader in following format: first name , last name +17. Take XML with readers and return all child nodes of each reader +18. Take XML with book or reader try write XPath expressions for each Xpath Axes operator diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4826c32 --- /dev/null +++ b/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + com.r11.xsd + xsd + 1.0 + + + 11 + 11 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter-api + 5.9.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.9.0 + test + + + + org.eclipse.jgit + org.eclipse.jgit + 6.3.0.202209071007-r + + + + + org.eclipse.jgit + org.eclipse.jgit.ssh.jsch + 6.3.0.202209071007-r + + + com.jcraft + jsch + + + + + com.github.mwiede + jsch + 0.2.4 + + + + org.eclipse.jgit + org.eclipse.jgit.ssh.apache + 6.3.0.202209071007-r + + + jaxb + activation + 1.0.2 + + + javax.xml.bind + jaxb-api + 2.3.0 + + + com.sun.xml.bind + jaxb-core + 2.3.0 + + + com.sun.xml.bind + jaxb-impl + 2.3.0 + + + jaxen + jaxen + 1.2.0 + + + net.sf.saxon + Saxon-HE + 11.4 + + + xml-resolver + xml-resolver + 1.2 + + + \ No newline at end of file diff --git a/src/main/java/com/r11/xpath/Task.java b/src/main/java/com/r11/xpath/Task.java new file mode 100644 index 0000000..c6d5e75 --- /dev/null +++ b/src/main/java/com/r11/xpath/Task.java @@ -0,0 +1,50 @@ +package com.r11.xpath; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "task") +@XmlAccessorType(XmlAccessType.FIELD) +public class Task { + + @XmlAttribute + private int id; + + private String name; + private String xpath; + + public Task() { + } + + public Task(int id, String name, String xpath) { + this.id = id; + this.name = name; + this.xpath = xpath; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getXPath() { + return xpath; + } + + public void setXpath(String xpath) { + this.xpath = xpath; + } +} diff --git a/src/main/java/com/r11/xpath/TasksContainer.java b/src/main/java/com/r11/xpath/TasksContainer.java new file mode 100644 index 0000000..28a2a16 --- /dev/null +++ b/src/main/java/com/r11/xpath/TasksContainer.java @@ -0,0 +1,29 @@ +package com.r11.xpath; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +@XmlRootElement(name = "tasks") +@XmlAccessorType(XmlAccessType.FIELD) +public class TasksContainer { + + @XmlElement(name = "task") + private final List tasks = new ArrayList<>(); + + public List getTasks() { + tasks.sort(Comparator.comparingInt(Task::getId)); + return tasks; + } + + public Task getOne(int id) { + return tasks.stream() + .filter(b -> b.getId() == id) + .findFirst() + .orElse(null); + } +} diff --git a/src/main/resources/xml/books.xml b/src/main/resources/xml/books.xml new file mode 100644 index 0000000..fb09f3c --- /dev/null +++ b/src/main/resources/xml/books.xml @@ -0,0 +1,189 @@ + + + + Hamlet + 2001-05-04 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + false + + + Macbeth + 2000-12-13 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + false + + + Harry Potter and the Sorcerer's Stone + 2005-04-29 + + J.K. + Rowling + 1965-07-31 + + true + + + The Long Walk + 2018-07-01 + + Stephen + King + 1947-09-21 + + true + + + Misery + 2018-01-31 + + Stephen + King + 1947-09-21 + + true + + + Think and Grow Rich + 2004-09-10 + + Napoleon + Hill + 1883-09-26 + 1970-11-08 + + true + + + The Law of Success + 1982-05-09 + + Napoleon + Hill + 1883-09-26 + 1970-11-08 + + false + + + Patriot Games + 1995-10-21 + + Tom + Clancy + 1947-04-12 + 2013-10-01 + + false + + + The Sum of All Fears + 1992-09-19 + + Tom + Clancy + 1947-04-12 + 2013-10-01 + + false + + + The Alchemist + 2017-02-20 + + Paulo + Coelho + 1947-08-24 + + false + + + Hamlet + 1994-06-01 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + false + + + Measure for Measure + 1990-03-23 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + false + + + Hamlet + 1989-05-05 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + true + + + Hamlet + 1999-05-30 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + true + + + The Law of Success + 2004-11-26 + + Napoleon + Hill + 1883-09-26 + 1970-11-08 + + true + + + Romeo and Juliet + 1997-02-08 + + William + Shakespeare + 1564-04-23 + 1616-04-23 + + true + + + The Alchemist + 2009-08-21 + + Paulo + Coelho + 1947-08-24 + + true + + diff --git a/src/main/resources/xml/readers.xml b/src/main/resources/xml/readers.xml new file mode 100644 index 0000000..8b3a6b4 --- /dev/null +++ b/src/main/resources/xml/readers.xml @@ -0,0 +1,80 @@ + + + + John + Burg + 45 + 32 + 57 + + + Steven + Pick + 29 + 27 + 12 + 91 + + + + Peter + Stock + 21 + 42 + 1 + 9 + 98 + 60 + + + Robert + Neat + 32 + 87 + 23 + 11 + 7 + 55 + + + John + Pale + 36 + 81 + + + Josh + Ericson + 46 + 8 + + + Patrick + Evans + 50 + + + Paul + Navy + 23 + 69 + 78 + + + Rob + Rockwell + 30 + 47 + + + Luis + Pocket + 52 + 10 + 83 + 2 + + diff --git a/src/main/resources/xpath/.gitkeep b/src/main/resources/xpath/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/xpath/XPathTasks.xml b/src/main/resources/xpath/XPathTasks.xml new file mode 100644 index 0000000..a2ccd66 --- /dev/null +++ b/src/main/resources/xpath/XPathTasks.xml @@ -0,0 +1,90 @@ + + + + + Take XML with books and calculate number of all books available. + Type the xpath here + + + Take XML with books and return first, third and last book from collection. + Type the xpath here + + + Take XML with books and return book with id = 7 from collection. + Type the xpath here + + + Take XML with books and return all books from year 2018. + Type the xpath here + + + Take XML with books and return all books which was released between 1990 and 1995 + Type the xpath here + + + Take XML with books and return book with title starting with word Harry + Type the xpath here + + + Take XML with books and return book witch contains word "Law" in the title + Type the xpath here + + + Take XML with books and return all attributes that are named id use // operator + Type the xpath here + + + Take XML with books and return all attributes that are named id don't use // operator + Type the xpath here + + + Take XML with books and return all node names in document + Type the xpath here + + + Take XML with books and return book written by authors which are still alive + Type the xpath here + + + Take XML with readers and sum age of all readers + Type the xpath here + + + Take XML with readers and return age node name without namespace for book with id = 7 + Type the xpath here + + + Take XML with readers and return lastname node name with namespace for book with id = 4 + Type the xpath here + + + Take XML with readers and return namespace for reader with id = 2 + Type the xpath here + + + Take XML with readers and return first name and last name for each reader in following format: first name , last name + Type the xpath here + + + Take XML with readers and return all child nodes of each reader + Type the xpath here + + + Take XML with book or reader try write XPath expressions for each Xpath Axes operator + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + Type the xpath here + + \ No newline at end of file