$25
Learn text and binary formats for data serialization
• Understand the differences between the most important formats
• This assignment will involve data representation formats, such as XML, JSON, Protocol Buffers, or MessagePack.
Resources
Maven:
• Students are advised to use Maven to manage their projects.
• Maven Tutorial: https://www.tutorialspoint.com/maven/ XML:
• XML: http://www.w3schools.com/xml
• JAXB Tutorial – Java.net: https://www.javatpoint.com/jaxb-tutorial Note: starting on version 9, the Java Architecture for XML Binding (JAXB) is no longer part of the Java Standard Edition. This causes a number of problems with the use of this architecture. You may resort to Maven for the rescue: https://stackoverflow.com/questions/43574426/how-to-resolve-java-langnoclassdeffounderror-javax-xml-bind-jaxbexception-in-j/46455026.
However, you should note that the version numbers of the dependencies are not right.
• Xalan: http://xml.apache.org/xalan-j/
JSON
• Homepage: https://developers.google.com/protocol-buffers/
Protocol Buffers
• Homepage: https://developers.google.com/protocol-buffers/ • Maven dependency: https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
• Compiler Download:
https://github.com/protocolbuffers/protobuf/releases
MessagePack
• Homepage: https://msgpack.org
Java XML Training Part (doesn’t count for evaluation)
Before you start, you may create a Maven project using the following command line, which initializes a “quickstart” archetype:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=uc.mei.is
-DartifactId=simple-jaxb -Dversion=0.0.1
Also, refer to https://mkyong.com/java/jaxb-hello-world-example/ for the dependencies you need to insert in the pom.xml file and for a base example using JAXB.
1. Using JAXB, write the Java classes and the marshalling code that outputs the following
XML:
a)
<?xml version="1.0" encoding="UTF-8"?>
<class>
<student>
<name>Alberto</name>
<age>21</age>
</student>
<student>
<name>Patricia</name>
<age>22</age>
</student>
<student>
<name>Luis</name>
<age>21</age>
</student>
</
class
>
b)
<?xml version="1.0" encoding="UTF-8"?>
<class>
<student id="201134441110">
<name>Alberto</name>
<age>21</age>
</student>
<student id="201134441116">
<name>Patricia</name>
<age>22</age>
</student>
<student id="201134441210">
<name>Luis</name>
<age>21</age>
</student>
</class>
c) (An XML equivalent to this is also acceptable)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated automatically. Don't change it. -->
<class xmlns="http://www.dei.uc.pt/EAI">
<student xmlns="" id="201134441110">
<name>Alberto</name>
<age>21</age>
</student>
<student xmlns="" id="201134441116">
<name>Patricia</name>
<age>21</age>
</student>
<student xmlns="" id="201134441210">
<name>Luis</name>
<age>21</age>
</student>
</class>
d)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!-- Generated automatically. Don't change it. -->
<h:class xmlns:h="http://www.dei.uc.pt/EAI">
<h:student id="201134441110">
<name>Alberto</name>
<age>21</age>
</h:student>
<h:student id="201134441116">
<name>Patricia</name>
<age>21</age>
</h:student>
<h:student id="201134441210">
<name>Luis</name>
<age>21</age>
</h:student>
</
h:class
>
e)
<?xml version="1.0" encoding="UTF-8"?>
<class>
<student id="201134441110">Alberto</student>
<student id="201134441116">Particia</student>
<student id="201134441210">Luis</student> </class>
2. Use an online tool or install a tool like trang to automatically produce the XSD for the following XML. Change the XSD, to ensure that <direction> can only be one of “dgsg|boinc” or “dgsg|xtremweb”, while <timestamp> must be positive. Note that you should always check if the tool inferred the correct schema, or if it requires some manual adjustment.
<?xml version="1.0" encoding="UTF-8"?>
<report timestamp="1308046204104" timezone="GMT" version="1.1">
<metric_data>
<metric_name>cpus_available</metric_name>
<timestamp>1308046204003</timestamp>
<value>0.0</value>
<type>uint32</type>
<units>cpus</units>
<spoof>EDGITest|fusion:EDGITest|fusion</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>gflops</metric_name>
<timestamp>1308046204056</timestamp>
<value>0.0</value>
<type>float</type>
<units>gflops</units>
<spoof>EDGITest|fusion:EDGITest|fusion</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>past_workunits</metric_name>
<timestamp>1308046204058</timestamp>
<value>0.0</value>
<type>uint32</type>
<units>wus</units>
<spoof>EDGITest|fusion:EDGITest|fusion</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>waiting_workunits</metric_name>
<timestamp>1308046204059</timestamp>
<value>0.0</value>
<type>uint32</type>
<units>wus</units>
<spoof>EDGITest|dsp:EDGITest|dsp</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>success_rate</metric_name>
<timestamp>1308046204061</timestamp>
<value>1.0</value>
<type>float</type>
<units>percentage</units>
<spoof>EDGITest|dsp:EDGITest|dsp</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>past_workunits_24_hours</metric_name>
<timestamp>1308046204064</timestamp>
<value>0.0</value>
<type>uint32</type>
<units>wus</units>
<spoof>EDGITest|fusion:EDGITest|fusion</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>cpus_available</metric_name>
<timestamp>1308046204066</timestamp>
<value>0.0</value>
<type>uint32</type>
<units>cpus</units>
<spoof>EDGITest|dsp:EDGITest|dsp</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>success_rate</metric_name>
<timestamp>1308046204067</timestamp>
<value>1.0</value>
<type>float</type>
<units>percentage</units>
<spoof>EDGITest|fusion:EDGITest|fusion</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
<metric_data>
<metric_name>gflops</metric_name>
<timestamp>1308046204092</timestamp>
<value>0.0</value>
<type>float</type>
<units>gflops</units>
<spoof>EDGITest|dsp:EDGITest|dsp</spoof>
<direction>dgsg|boinc</direction>
</metric_data>
</report>
3. Now, create an XML file with a catalog of books and use XSLT to display the books in an HTML table. A simple way of accomplishing this task is by means of using XalanJava, referenced above.