Posts

Showing posts with the label Parsing

Web service for translating between two languages

Jersey REST service for translating between two languages. It's just a basic concept but it's working. web.xml 1: <?xml version="1.0" encoding="UTF-8"?> 2: 3: <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 4: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5: xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 6: version="3.1"> 7: <display-name>TranslateWS</display-name> 8: <servlet> 9: <servlet-name>Jersey REST Service</servlet-name> 10: <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 11: <!-- Register resources and providers under com.vogella.jersey.first package. --> 12: <init-param> 13: <param-name>jersey.config.server.provider.packages</param-name> 14: <param-va...

XML parsing with XPath

Parsing and extracting data from XML file with XPath. The output displays detailed information on all books whose price is higher than 10, which were published after 2005. bookCatalog.xml 1: <?xml version="1.0" encoding="UTF-8"?> 2: <!DOCTYPE root SYSTEM "bookCatalogDTD.dtd"> 3: 4: <catalog> 5: <book id="bk101"> 6: <author>Gambardella, Matthew</author> 7: <title>XML Developer's Guide</title> 8: <genre>Computer</genre> 9: <price>44.95</price> 10: <publish_date>2000-10-01</publish_date> 11: <description>An in-depth look at creating applications 12: with XML.</description> 13: </book> 14: <book id="bk102"> 15: <author>Ralls, Kim</author> 16: <title>Midnight Rain</title> 17: <genre>Fantasy</genre> 18: ...

Parsing text and creating a collection of objects

The following string is given, which is a record read from a outer source: String text = "John.Davidson/05051988/Belgrade Michael.Barton/01011968/Krakov Ivan.Perkinson/23051986/Moscow"; It is necessary to create a logic that will extract data from this record: Data needed:     - name     - lastname     - date of birth     - place of birth Read and extracted data from the string needs to be used for filling the fields of the Person type object; therefore, it is necessary to create a class Person, as well as the appropriate fields within it. So, in the class Person should be a constructor with these 4 given fields. Then, in the Test class, after creating an object and filling in his fields, the Person type object should be placed in a collection (for example, in the list) and finally go through that collection and print data about people. The date of birth field should be LocalDate type. When printing data on people, in the end, it wou...