Skip to content
Snippets Groups Projects
Commit 50b0fcec authored by Goik Martin's avatar Goik Martin
Browse files

Removin solution from Exam (previous commit)

parent 8a842c9e
No related branches found
No related tags found
No related merge requests found
......@@ -5,19 +5,41 @@ DROP TABLE IF EXISTS Section;
-- Read the exercise's documentation and add your schema here. You may
-- re-use subsequent INSERT statements or adapt them to your schema.
-- CREATE TABLE ...
CREATE TABLE Section(
INSERT INTO Section VALUES ('categories', 'XML Document categories', NULL, 'new', 1);
INSERT INTO Section VALUES ('wellFormed', 'Well-formed documents', 'categories' ,NULL, 2);
id CHAR(255) NOT NULL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
parent CHAR(255) NULL REFERENCES Section,
revisionflag CHAR(7) NULL,
orderNo INT NOT NULL GENERATED ALWAYS AS IDENTITY UNIQUE,
CHECK(revisionflag IN ('new', 'changed', 'deleted'))
);
INSERT INTO Para VALUES (
'categories', 'Documents belonging to this category do not adhere to any schema.','changed', 3);
CREATE TABLE Para (
parent CHAR(255) NOT NULL REFERENCES Section,
para TEXT,
revisionflag CHAR(7) NULL,
orderNo INT NOT NULL GENERATED ALWAYS AS IDENTITY UNIQUE,
CHECK(revisionflag IN ('new', 'changed', 'deleted'))
);
INSERT INTO Section (id, title, parent, revisionflag) VALUES ('categories', 'XML Document categories', NULL, 'new');
INSERT INTO Section (id, title, parent, revisionflag) VALUES ('wellFormed', 'Well-formed documents', 'categories' ,NULL);
INSERT INTO Section VALUES ('valid', 'Valid documents', 'categories', NULL, 4);
INSERT INTO Para VALUES ('valid', 'Valid documents require a schema.', 'changed', 5);
INSERT INTO Para VALUES ('valid', 'Common standards are DTD, XML Schema and Relax-NG.',NULL, 6);
INSERT INTO Para (parent, para, revisionflag) VALUES (
'categories', 'Documents belonging to this category do not adhere to any schema.','changed');
INSERT INTO Section VALUES ('api', 'Available APIs', NULL, 'deleted', 7);
INSERT INTO Para VALUES ('api', 'We introduce SAX and DOM here.', NULL, 8);
INSERT INTO Para VALUES ('api', 'Some APIs offer multiple language bindings.', NULL, 9);
\ No newline at end of file
INSERT INTO Section (id, title, parent, revisionflag) VALUES ('valid', 'Valid documents', 'categories', NULL);
INSERT INTO Para (parent, para, revisionflag) VALUES ('valid', 'Valid documents require a schema.', 'changed');
INSERT INTO Para (parent, para, revisionflag) VALUES ('valid', 'Common standards are DTD, XML Schema and Relax-NG.',NULL);
INSERT INTO Section (id, title, parent, revisionflag) VALUES ('api', 'Available APIs', NULL, 'deleted');
INSERT INTO Para (parent, para, revisionflag) VALUES ('api', 'We introduce SAX and DOM here.', NULL);
INSERT INTO Para(parent, para, revisionflag) VALUES ('api', 'Some APIs offer multiple language bindings.', NULL);
SELECT * FROM Section;
SELECT * FROM Para;
\ No newline at end of file
package de.hdm_stuttgart.mi.sda1;
import org.jdom2.*;
import org.jdom2.filter.ElementFilter;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Book2Rdbms {
public class Book2Rdbms implements AutoCloseable {
private Connection conn;
private Document doc;
private Connection conn;
public Book2Rdbms() {
try {
conn = DriverManager.getConnection(
"jdbc:postgresql://localhost/hdm", "hdmuser", "XYZ");
} catch (SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
private Element book;
final SAXBuilder builder = new SAXBuilder();
try {
doc = builder.build(new File("Schema/sampledata.xml"));
//getClass().getClassLoader().getResource("Schema/sampledata.xml"));
} catch (JDOMException e) {
e.printStackTrace();
System.err.println("Unable to parse input: " + e);
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable to read input: " + e);
System.exit(1);
}
}
public void execute() {
final XPathExpression<Element> xpathSearchPara =
XPathFactory.instance().compile(
"//para" ,
new ElementFilter(),
null ,
Namespace.getNamespace(null));
public Book2Rdbms(
) {
try {
conn = DriverManager.getConnection(
"jdbc:postgresql://localhost/hdm", "hdmuser", "XYZ");
System.out.println("Java stream:");
xpathSearchPara.evaluate(doc).stream().
map(Element::getText).forEach(System.out::println);
System.out.println("\nSimple loop:");
for (final Element e: xpathSearchPara.evaluate(doc)) {
System.out.println(e.getText());
}
} catch (SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
final SAXBuilder builder = new SAXBuilder();
try {
book = builder.build(new File("Schema/sampledata.xml")).getRootElement();
} catch (JDOMException e) {
e.printStackTrace();
System.err.println("Unable to parse input: " + e);
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable to read input: " + e);
System.exit(1);
}
}
public void execute() {
System.out.println(book.getChild("title"));
}
@Override
public void close() {
try {
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment