(15 points)
The goal in this year's exercise is to develop an XML-based format to represent data for an auction house (like eBay). In Exercise 1 you will create an XML Schema and XML document and in Exercise 2 you will be querying and transforming this document with XML-related technologies.
An auction house offers products. A user can place a bid on a specific product. After a set date, the auction for a product ends. The user with the highest bid wins the product.
Remark: The following data format can be seen as a database for an auction house.
This exercise consists of three parts. First, we will use DOM and SAX to access and modify XML documents. Second, we will evaluate an xQuery expression over an XML document. And third, we will use XSLT to transform the XML document into a Webpage.
resources/auctions.xml
and
resources/auctions.xsd
. These files will be used and are configured as input for the
ant targets.resources/auctions.xsd
. Imagine that your application is divided into a client that displays the auction house and a server that processes and manages the auction house.
The auction house displays its product on a webpage (the client). The user chooses a product and places a bid. The client sends the bid to the server, which stores and processes the auction house data (in an XML document). The client uses the following "bid" XML document for this communication:
<bid product="2">
<user>Lisa</user>
<bid>500</bid>
</bid>
This XML document states that the user "Lisa" placed a bid of "500" on product with id "2".
Your goal is to manipulate the auctions.xml
document with DOM in such a way, that the above "bid" is stored in the document.
The "bid" document is parsed using SAX.
You have to ensure that your resulting document validates against the given auctions.xsd
. Additionally, you have to check if the placed bid fulfills the following criteria:
auctionEnd
is before the currentDate) nor is expired (auction doesn't have an expired
child element).The template provides you two classes. The class SSD
contains the main program logic. The class Bidding Handler
is used
as a SAX handler for parsing the "bid" document and manipulating the auction house document. A detailed description follows:
static DocumentBuilderFactory documentBuilderFactory
: static DocumentBuilder documentBuilder
: static void main(String [] args) throws Exception
: initialize
and transform
.static void initialize() throws Exception
: documentBuilderFactory
and the documentBuilder
variables.static void transform(String inputPath, String bidPath, String outputPath) throws Exception
: inputPath
variable. Second, you have to set up the SAX parser, in order to parse the XML document given in the bidPath
variable.
For this you have to create an instance of the BiddingHandler
class, which needs the previously created Document as an argument to its constructor. Third, you parse
the bid document. The BiddingHandler
will change the document. Last, retrieve this document with the method getDocument()
and store this document
in the file given by the outputPath
variable.static void exit(String message)
: static XPath xPath
: Document auctionsDoc
: String eleText
: BiddingHandler(Document doc)
: void characters(char[] text, int start, int length)
: eleText
variable.Document getDocument()
: startElement
, etc.) and modify the auctionsDoc
document.The code implemented in src/ssd/SSD.java
can be run using three program arguments. The first is an auction house document as input (e.g. auctions.xml
from exercise 1 or the file located in the resources
folder). The second is a "bid" document (e.g. resources/auction-bid.xml
). The last
is an auction house document as output (e.g. output/auctions.xml
). We have configured two ant-targets:
ant run-dry
: resources/auctions-bid.xml
to the auction house document resources/auctions.xml
and
stores the output to output/auctions.xml
.ant run-persistent
: resources/auctions-bid.xml
to the auction house document resources/auctions.xml
and
stores the output to resources/auctions.xml
. Therefore, the input file will be overwritten and the "bid" is made persistent.resources/auctions-sample-out.xml
that shows the output of the program by applying resources/auction-bid.xml
to resources/auctions.xml
.
XPathExpression xpathExpr = xPath.compile("//users");
NodeList playerList = (NodeList)xpathExpr.evaluate(auctionsDoc,
XPathConstants.NODESET);
SSD.java
and BiddingHandler.java
In this exercise we will create an XQuery that evaluated over an auction house document, will give you a list of users together with the won bids.
The output should look as follows:
<?xml version="1.0" encoding="UTF-8"?>
<won>
<user name="Bart">
<product value="450">Web Engineering</product>
<product value="150">XML in a Nutshell</product>
</user>
<user name="Homer"/>
<user name="Lisa">
<product value="300">The Great Gatsby (Movie + Soundtrack)</product>
</user>
</won>
The meaning of the document is as follows: The user "Bart" won the products "Web Engineering" (with value "450") and "XML in a Nutshell" (with value "150). The user "Homer" has not won any products. The user "Lisa" won the products "The Great Gatsby (Movie + Soundtrack)" (with value "300").
The elements won should be ordered by user ascending and the elements product by value descending.
You can write this query in src/xquery.xq
. The query can be evaluated over resources/auctions.xml
using the following command:
ant run-xquery
output/xquery-out.xml
.
xquery.xq
Create an XSLT stylesheet src/auctions.xsl
, which transforms a (for the schema resources/auctions.xsd
) valid XML document (like resources/auctions.xml
) into an HTML document specified as follows:
The HTML document should give an overview of the products contained in an auction house auctions.xml
document. For each product give the name and the description. Also list the total number of bids and each bid for the product. The bid with the highest value should be in red color.
An example output is given here.
The transformation using the stylesheet in src/auctions.xsl
from resources/auctions.xml
to output/auctions.html
can be run using the following command:
ant run-xslt
output/auctions.html
.
auctions.xsl
In order to create a zip file ssd-exercise2-ss16.zip
you have to use the following command:
ant zip
This zip file has to be uploaded until 08.06.2016 23:55 in TUWEL. We will grade the last uploaded solution.
You can receive at most 15 points for Exercise 3. During the assignment discussion we will not only check your solution for correctness, but will also ask some questions regarding the used technologies.
To obtain the full number of points your solution has to be solved correctly and you have to be able to explain it. Copied solutions are awarded 0 points!
In your own interest come ontime to your assignment discussion or else we don't guarantee that your solution is completely checked in the remaining time of the reserved slot.