Kap7_XML

Werbung
Vertiefungsmodul Daten-, Informations- und Wissensmanagement
Kap 7: XML und XML Datenbanken
Erik Wilde dret.net/lectures/xml-fall13/
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
1
Agenda
• XML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
2
Literatur @2016
•
•
http://dret.net/lectures/xml-fall06/ super Kurs durchs GANZE XML aus Stanford
http://www.informatik.uni-giessen.de/staff/brass/xml00/ Deutscher Kompaktkurs
•
http://www.teialehrbuch.de/Kostenlose-Kurse/Datenbankentwicklung-mit-PostgreSQL9/13.1.7-Beispiel-139-Erstellen-von-Elementwäldern-mit-XMLFOREST.html für XML/SQL
@2015 gute Basis für den Kurs
http://www.stylusstudio.com/sqlxml_tutorial.html
http://dbs.uni-leipzig.de/file/dbs2-ss10-kap6.pdf info on SQL/XML nach dem STD §§ und
sehr schön on XQuery in dt. mit guten Details §§
http://dbs.uni-leipzig.de/file/dbs2-ss10-kap5.pdf XML allgemein, aber sehr schön in dt.
on Namensräume und Schemata
•
•
•
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
3
XML Intro zum Ansehen @2016
• http://www.youtube.com/watch?v=dfeoEb6XAZk
• http://lots.uni-leipzig.de/xqtrain/index.jsp ist ein interaktiver
Trainer für XML
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
4
Bedeutung semistrukturierter Bestände
•
In vielen Fällen von Dokumenten ist die Beschreibung aller Eventualitäten fast unmöglich oder würde im
relationalen Modell zu Tabellen mit –zig NULLS führen
–
–
•
Beispiel: Handelsfactura
Beispiel: Hobbies der Freunde
Einzelne Nutzer haben ein Interesse daran, gewisse Strukturen in „ihren“ Dokumenten vorzugeben
Beispiel: Bestellung
– Gewichte in kg oder US_lb, aber nicht imperialPounds (lb) , Stones ….
– Zu jeder Adresse muss es mindestens 1 Eintrag „Straßenadresse“ geben
– wenn Angabe zum Versand, dann: Größe eines Kartons muss immer 3 Längendimensionen und Gewicht haben
– Die Bestellnummer jedes Artikels muss 8 stellig numerisch sein
– Die Bestellnummer muss eine derzeit gültige sein (*)
•
WI
… und Ersteller solcher Dokumente sollen die Gültigkeit möglichst „schon bei sich“ (d.h. ohne meine Datenbank
mit einem illegalen INSERT-Versuch zu belasten) prüfen können (bei (*) problematisch, da Zugriff auf aktuelle
Datenbank unvermeidlich)
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
5
Beispiel
⊳ Freund 1 Name Meier
Hobby BriefmarkenSammeln
⊳Freund2 Name Meyer
Hobby BriefmarkenSammeln
⊳Freund3 Name Müller
Hobby Kochen
⊳Freund4 Name Huber
Hobby Schach
⊳Freund4 Name Schmidt
Hobby Schach
⊳Freund 5 Name Huber
Hobby Tiefseetasuchen
Länder Deutschland, Liechtenstein, Indisch
Themen Blumen, Schach
Länder Deutschland
Jahrgänge 1900-1945
Spezialitäten Huhn, Eintöpfe, Indisch
Niveau Meister
Eröffnungen Pirc, Orang-Utan, Indisch
Niveau Großmeister
Eröffnungen Italienisch, Nimzo- Indisch
Tauchtiefen 20..100 m
Meere Rotes Meer, Indischer Ozean, Karibik
Probleme
⊳ Längen unterschiedlich, selbst beim gleichen Feld
⊳ Unterschiedliche Feldzahl und –typ (Tauchtiefe!)
⊳ Unterschiedliche Semantik: Zahl «1930» ist Jahr, nicht Tauchtiefe ; Wer kämpft mit mir für den Schutz der Orang-Utans
⊳ Nackte Stringsuche bringt wenig: ich fahre nach Indien, wem kann ich was mitbringen?
⊳ rDBMS/SQL hätte extrem viele „Nulls“ und (spätestens) für jedes neues Hobby müsste man neue Tabelle/Spalten einführen
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
7
Anforderungen
Verarbeitungsoptionen
•
•
Via leicht anzuschließende Programmierschnittstellen und/oder im Browser
Mit eigener „Programmiersprache“, die die Datenbank mitbringt
Beispiele
•
Für alle Bestellungen, bei denen wir Vorwahl = 0361 finden …
• drucke Straßenadresse und Ansprechpartner
•
Für alle Freunde, bei denen man unter Hobbies irgendwo einen Verweis auf LAND = „Mali“ findet …
• drucke den Namen des Freunds und die Hobbies
 (wieder einmal) hohes Interesse an einer weltweiten Standardisierung auf dieser (Meta)ebene
•
WI
Nochmals schwieriger als im SQL, da weniger strukturiert; Programmierschnittstelle hat Vorrang vor
einer reinen GUI (außer innerhalb der Lehre)
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
6
Gestaltungsprinzipien XML
•
XML = eXtended Markup Language
–
Semantische Auszeichnung
• Johann Friedrich der Gütige 
• <namenspatron> Johann Friedrich der Gütige </namenspatron>
• <buendnis><buendnisname>Schmalkaldischer Bund </buendnisname>
<beteiligter> Johann Friedrich <Beiname>der Gütige</Beiname> </beteiligter>
<beteiligter> <Titel>Herzog</Titel> Philipp von Braunschweig-Grubenhagen</beteiligter>
<beteiligter> <Titel> Herzog </Titel> Ernst von Braunschweig-Lüneburg</beteiligter>
</buendnis>
 Regeln zur Ausgestaltung dieser semantischen Auszeichnung
– Ursprüngliche Zielgruppe (d.i. „Text mit Formatierung ausgezeichnet“ (sog. „narrative documents“), ist heute nur noch kleiner
Teil der Anwendungen
•
•
•
Tags sind in < > geklammert. Den Text zwischen <tag> und </tag> nennt man ‚mit dem tag ausgezeichnet‘.
( Nebenbemerkung: Kurzform <tag/> für <tag></tag> )
Tags können Attribute tragen <H1 size=„14pt“ font=„Arial“> … </H1>
Einige weitere, eher seltene Elemente
•
•
•
•
WI
<?processing instruction ?>
z.B. PHP Programm oder verwendeter Code
<![CDATA[Inhalt]]>
<!– Kommentar aus XML Sicht -->
<? xml-Prolog vor dem Dokument>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
8
‚well formedness‘ als Minimalkriterium
•
Tags treten immer nur geschachtelt auf
–
–
•
•
<tag1> … <tag2> ….</tag2> …</tag1>
<tag1> …. <tag2> … </tag1> …. </tag2> NO !!!
In einem einzelnen Dokument gibt es genau 1 Wurzelelement
Attributnamen kommen nicht mehrfach vor
–
<H1 font=„Arial“ font=„Times“> NO !!!
•
Wohlgeformte Dokumente lassen sich als Dokumentenbaum darstellen. Viele Verarbeitungsstrategien (und die meisten parser =
Verarbeitungssoftware) basieren auf der Operationen auf diesem Dokumentenbaum. (siehe die folgenden Abschnitte)
•
Wohlgeformtheit wird als Minimalkriterium gesehen http://dret.net/lectures/xml-fall13/basics ist eine gute Einführung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
9
Beispiel
<?xml version="1.0" encoding="UTF-8" ?>
<ixq:customers xmlns:ixq="http://www.ipedo.com/XQueryExample">
<customer>
<custno>9000</custno>
<name>
Wird gleich erklärt
<firstname>Joe</firstname>
<lastname>Anderson</lastname>
</name>
<email>[email protected]</email>
<phone>1-888-555-1234</phone>
</customer>
<customer>
<custno>1001</custno>
WI
<name>
<firstname>Andy</firstname>
<lastname>Shaperd</lastname>
</name>
<email>[email protected]</email>
</customer>
<customer>
<custno>1003</custno>
<name>
<firstname>Amanda</firstname>
<lastname>Johnson</lastname>
</name>
<email>[email protected]</email>
</customer>
</ixq:customers>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
10
Beispiel (2):
<xml>
<LIEFERADRESSE>
<STREETADDRESS>
<PLZ> 07743 </PLZ> <ORT> JENA-Lobeda </ORT>
<STRASSE> Carl_Zeiss_Str </STRASSE> <HNR> 7 b </HNR>
</STREETADDRESS>
<KONTAKT_TF> 07740 </ KONTAKT _TF> °°°°°°
<AusfahrerInfo> <Ansprechpartner>Müller , Huber </Ansprechpartner>
<KONTAKT _TF> 07740 </ KONTAKT _TF>
<Rampe> 2 </Rampe>
</AusfahrerInfo>
</LIEFERADRESSE>
.... Weiter geht es auf der Folgeseite
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
11
Beispiel (2) Fortsetzung:
<RECHNUNGSADRESSE>
<STREETADDRESS>
<PLZ> 07740 </PLZ> <ORT> JENA-Winzerla </ORT>
<STRASSE> E-Plus-Platz </STRASSE> <HNR> 7 </HNR>
</STREETADDRESS>
< KONTAKT _TF> 07740-200 </ KONTAKT _TF>
</RECHNUNGSADRESSE>
<BESTELLARTIKELLISTE>
<BESTELLARTIKEL>
<NAME> Nagel 30/40 </NAME> <NUMMER> 30400001 </NUMMER>
<AUSWEICHARTIKEL>
<NAME> Nagel 40/40 </NAME> <NUMMER> 3132</NUMMER>
</AUSWEICHARTIKEL>
</BESTELLARTIKEL>
2. Artikel ohne
Ausweichartikel
<BESTELLARTIKEL>
<NAME> Ziernagel 9230/40 </NAME> <NUMMER> 78123 </NUMMER>
</BESTELLARTIKEL>
Die <tag> ... </tag>
Strukturen müssen
stets geschachtelt
sein
<BESTELLARTIKEL>
<NAME> Hammer 300g </NAME> <NUMMER> 002002300 </NUMMER>
<AUSWEICHARTIKEL>
<NAME> Nagel 40/40 </NAME> <NUMMER> 3132</NUMMER>
</AUSWEICHARTIKEL>
</BESTELLARTIKEL>
</BESTELLARTIKELLISTE>
</xml>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
12
Einsatzbeispiel HTML (in der strikten xhtml-Form) im Web
<html>
quick</li>
<head>
<li>
<title>HTML Online Editor Sample</title>
</head>
<body>
and easy?</li>
</ol>
<h1>
</li>
<li>
Online HTML Editor</h1>
<p>
text area - go on!</p>
<p>
text</strong>. </p>
<p>
Is it... FREE?</li>
This is an online HTML editor. Try editing this
</ul>
<p>
Feel free to use this online HTML editor for
generating HTML code for your own website, MySpace page, etc. To view the source
code, simply click on the "Source" button above.</p>
<hr />
<p style="font-size: 10px;">
<a href="http://www.quackit.com/html/onlinehtml-editor/">Online Editor Site </a></p>
</body>
Here is some <strong>sample bold
Here is a checklist for a good online editor:</p>
<ul type="square">
<li>
Is it a WYSIWYG editor?
(WYSIWYG means "What You See Is What You Get" - just like this
editor!)</li>
<li>
Does it generate valid
HTML code?</li>
<li>
Is it ...
<ol>
<li>
</html>
•
Aus http://www.quackit.com/html/online-html-editor/
•
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
13
… zugehöriges Rendering im Browser
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
14
http://www.cafeconleche.org/books/bible3/chapters/ch15.html
An XML Periodic Table with Two Atoms: Hydrogen and
Helium
<?xml version="1.0"?>
<?xml-stylesheet type="application/xml" href="15-2.xsl"?>
<PERIODIC_TABLE>
<ATOM STATE="GAS">
<NAME>Hydrogen</NAME>
<SYMBOL>H</SYMBOL>
<ATOMIC_NUMBER>1</ATOMIC_NUMBER>
<ATOMIC_WEIGHT>1.00794</ATOMIC_WEIGHT>
<BOILING_POINT
UNITS="Kelvin">20.28</BOILING_POINT>
<MELTING_POINT
UNITS="Kelvin">13.81</MELTING_POINT>
<DENSITY UNITS="grams/cubic centimeter">
<!-- At 300K, 1 atm -->
0.0000899
</DENSITY>
</ATOM>
WI
<ATOM STATE="GAS">
<NAME>Helium</NAME>
<SYMBOL>He</SYMBOL>
<ATOMIC_NUMBER>2</ATOMIC_NUMBER>
<ATOMIC_WEIGHT>4.0026</ATOMIC_WEIGHT>
<BOILING_POINT UNITS="Kelvin">4.216</BOILING_POINT>
<MELTING_POINT UNITS="Kelvin">0.95</MELTING_POINT>
<DENSITY UNITS="grams/cubic centimeter"><!-- At 300K -->
0.0001785
</DENSITY>
</ATOM>
</PERIODIC_TABLE>
http://www.cafeconleche.org/books/bible3/chap
ters/picture1.jpg
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
15
and the tree
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
16
Namespaces und Schemata
•
•
•
•
•
WI
Mittels Schemata kann man gewisse Formvorschriften erteilen (Details auf Folgefolien), z.B. verlangt
PersonenSchema1: „es muss immer ein name-Tag vorkommen und unter <name> muss immer genau 1 <rufname>
kommen.“ Ein Dokument (oder ein Teil davon) kann darauf verpflichtet werden, dass nur nach diesem Schema
formatierte Tags vorkommen
Aber: FirmenSchema verlangt, dass es immer genau 1 Name-Tag gibt mit genau 1 <rechtsform> darunter
Was tun, wenn man in einem Dokument beide Schemata braucht? Oder gar FirmenSchema verlangt, dass die
Angeben zu <geschäftsführer> nach PersonenSchema1 formatiert sind?
Umbenennung (also z.B.: PersonenSchema1 verlangt <completeName> statt <name>) löst das Problem nicht, da man
nie weiß, wo PersonenSchema1 noch verwendet wird und ggf neue Kollisionen ausgelöst werden.
Namespaces als Lösung funktionieren wie Telefonvorwahlen mit Kurzwahl (005982  Montevideo)
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
17
http://dret.net/lectures/xml-fall06/xsd1
RELAX
valid
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
18
XML Namespaces (i)
•
•
•
•
Ein Schema kann andere Schemata importieren
… oder das Dokument importiert mehrere Schemata (die z.B. Unterschiedliche Entities modellieren)
Jetzt kann nicht mehr garantiert werden, dass ein Tag wie <name> eindeutig definiert ist
Grundidee <bestellung:name rolle=„Lieferant“ > sagt: diese entity ist nach den Regeln des bestellung –Schemas
formatiert
–
•
WI
… damit sagt man implizit meist auch: dieser Tag bezieht sich auf Bestellung
http://www.liquid-technologies.com/Tutorials/XmlSchemas/XsdTutorial_04.aspx erklärt
es gut
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
19
XML Namespaces (ii) aus http://de.wikipedia.org/wiki/Namensraum_(XML)
XML-Namensräume (englisch „XML namespaces“) werden benutzt, um das Vokabular eines XML-Dokumentes eindeutig zu identifizieren und um in einem einzelnen
Dokument mehrere XML-Sprachen zu mischen. Ihre Funktionsweise ist mit Vorwahlen bei Telefonnummern zu vergleichen.
Zum Beispiel beschreibt das <p>-Element in XHTML einen Absatz; in einer XML-Sprache für eine Personendatenbank könnte <p> ein Element für eine Person
darstellen. Namensräume erlauben, diese Elemente eindeutig zu unterscheiden.
Für Namensräume wird das Attribut xmlns (für engl.: XML Namespace) verwendet:
<html xmlns="http://www.w3.org/1999/xhtml">
... restliche HTML-Datei
</html>
Alle Kindelemente von <html>, also Elemente innerhalb von <html>...</html>, gehören hier zum Namensraum http://www.w3.org/1999/xhtml. Namensräume
können auch verschachtelt werden:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://www.w3.org/1998/Math/MathML">
... XHTML-Elemente
<m:math>
... MathML-Elemente mit m:-Präfix
</m:math>
... XHTML-Elemente
</html>
Bei Namensräumen heißt das, dass Attribute nicht im Namensraum des Elements stehen, in dem sie notiert sind, sondern vorgabemäßig im Null-Namensraum.
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
20
Validierung gegen sog. Schemata
•
•
Benutzer möchte zusätzliche Restriktionen angeben und nur solche Dokumente
akzeptieren, die diesen genügen. Ein entsprechender Parser kann ein XMLDokument dann gegen diese Restriktionen validieren
Alternative, unterschiedlich mächtige Systeme zur Spezifikation dieser Bedingungen
– DTD (Document Type Definition) --- weitgehend veraltet
– XML Schema
•
•
•
•
Welche Attribute, ggf. Attribut-Werte
Numerisch ?
Elemente ; zulässige Kindelemente, wie oft …
Ein XML Schema ist selbst ein XML Dokument
– Weitere Systeme (z.B. Relax NG, oder Schematron) – deutlich weniger verbreitet
•
Mächtige XML Editoren lassen
– Schemata erstellen
– Gegen Schemata validieren
– EDITIX http://free.editix.com/xmleditor-comparison.html schaut gut aus
– http://xmlfox.com/validate_xml.htm nette Intro
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
21
Standardschemata
Idee: an einer Stelle im „Netz“ („Schema location“ wird in einer Datei niedergelegt, wie XML-Dokumente
auszusehen haben, die dieser Spezifikation genügen
–
–
–
z.B. zur Beschreibung mathematischer Formeln
Oder Berechnungsmodellen
…
Validierer online z.B. bei
http://www.xmlvalidation.com/example.html
http://tools.decisionsoft.com/schemaValidate.html
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
22
Fast richtiges Dokument und zugehöriges Schema
<?xml version="1.0" encoding="UTF-8"?>
<addresses
xmlns:xsi=http://www.w3.org/2001/XMLSchem
a-instance
xsi:noNamespaceSchemaLocation='test.xsd'>
sagt: tags, die in keinem
<address>
Namespace leben, sollen nach
test.xsd validiert werden
<name>Joe Tester</name>
<street>Baker street 5</street>
<wrongExtraField/>
</wrongClosingTag><!– defying wellformedness -->
</addresses>
Quelle:
http://www.xmlvalidation.com/example.html
Mit Validator
WI
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name="addresses">
<xs:complexType>
<xs:sequence>
<xs:element ref="address" minOccurs='1' maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" minOccurs='0' maxOccurs='1'/>
<xs:element ref="street" minOccurs='0' maxOccurs='1'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type='xs:string'/>
<xs:element name="street" type='xs:string'/>
</xs:schema>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
23
Komplexes Schema einer Bestellung
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/po.xsd"
xmlns="http://tempuri.org/po.xsd"
elementFormDefault="qualified">
<xs:annotation>
<xs:documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</xs:documentation>
</xs:annotation>
<xs:element name="purchaseOrder"
type="PurchaseOrderType"/>
<xs:element name="comment" type="xs:string"/>
Quelle: msdn.microsoft.com/en-us/library/ms256129.aspx
WI
<xs:complexType name="PurchaseOrderType">
<xs:sequence>
<xs:element name="shipTo" type="USAddress"/>
<xs:element name="billTo" type="USAddress"/>
<xs:element ref="comment" minOccurs="0"/>
<xs:element name="items" type="Items"/>
</xs:sequence>
<xs:attribute name="orderDate" type="xs:date"/>
</xs:complexType>
<xs:complexType name="USAddress">
<xs:annotation>
<xs:documentation>
Purchase order schema for Example.Microsoft.com.
Copyright 2001 Example.Microsoft.com. All rights reserved.
</xs:documentation>
<xs:appinfo>
Application info.
</xs:appinfo>
</xs:annotation>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
24
Komplexes Schema einer Bestellung
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="zip" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="country" type="xs:NMTOKEN"
fixed="US"/>
</xs:complexType>
<xs:complexType name="Items">
<xs:sequence>
<xs:element name="item" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="productName" type="xs:string"/>
WI
<xs:element name="quantity">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:maxExclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="USPrice" type="xs:decimal"/>
<xs:element ref="comment" minOccurs="0"/>
<xs:element name="shipDate" type="xs:date" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="partNum" type="SKU" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- Stock Keeping Unit, a code for identifying products -->
<xs:simpleType name="SKU">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-[A-Z]{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
25
Und eine zugehörige Bestellung
<?xml version="1.0"?>
<purchaseOrder xmlns="http://tempuri.org/po.xsd"
orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
WI
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
26
Komplexes Schema einer Bestellung
Hinweis:
• im Eingangsbeispiel zu <addresses> wurden die Struktur aller Elemente (zB address) direkt
beschrieben
• im Bestell-Beispiel sagen wir: purchaseOrder ist vom Typ purchase orderType, den wir dann
getrennt beschreiben
in XSD sind beide Wege möglich
Vorteil von (2): wenn wir anderswo ein Element „backorders“ gleicher Struktur haben, müssen
wir nur noch sagen „backorders ist vom purchase order type“
erleichterte Wiederverwendung und Wartung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
27
Typische Leistungen eines Schemas
•
•
•
•
•
•
Beschränke die „Occurrences“ mit min und max
Beschränke auf gewisse Eigenschaften („ein String, der mit 0..9 beginnt“)
Erlaube gewisse Reihenfolgen der Tags
… und ggf. weitere Elemente am Ende
wende auf Attribute und Elemente an
Definiere Neue Datentypen
–
„complex types“
•
•
•
•
–
–
•
WI
Aus elementaren Typen
Durch Restriktion
Enumeration
Erweiterung anderer Complex Types
Neu in XSD 1.1 : „Referentielle Integrität“ im Wertebereich
Min occurs / max occurs
Schema kann Bestandteil eines Dokuments sein, vom Dokument aus via URL referenziert
werden oder vom Benutzer als zwei Inputs einem Validator übergeben werden
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
28
Kernspezifikationen innerhalb des Schemas
Quelle - http://www.w3schools.com/Schema/schema_example.asp
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
29
Komplexität der XSD
•
•
•
•
WI
The [W3C XML Schema] standard is versatile, allowing for programming concepts such as inheritance and
type creation, but it is complex. The standard itself is highly technical and published in 3 different parts,
making it difficult to understand without committing large amounts of time.
https://en.wikipedia.org/wiki/XML_Schema_Editor
 Schema Editors als Software
Z.B. http://free.editix.com/ oder Foxit oder Oxygen XML Editor
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
30
XSD „schema description“
•
•
•
www.w3schools.com/schema/schema_example.asp !!!
www.liquid-technologies.com/Tutorials/XmlSchemas/XsdTutorial_01.aspx ff !!!
dbs.uni-leipzig.de/file/dbs2-ss10-kap5.pdf Deutsch on schemata !!!
•
•
http://www.informit.com/articles/article.aspx?p=31477 on referential Integrity !!!
http://www2.informatik.hu-berlin.de/~obecker/Lehre/SS2002/XML/11c-schema.html GANZ
hervorragend on Schemata & referential integrity; gut zu verstehen
•
http://en.wikipedia.org/wiki/XML_Schema_%28W3C%29
•
Tutorial http://www.w3schools.com/schema/schema_howto.asp
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
31
Beispielschema: Buchbesprechung
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="DE">
Buchbestellung Schema für Example.com.
Copyright 2001 Example.com. Alle Rechte vorbehalten.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="Bestellung" type="BestellungTyp"/>
<xsd:element name="Kommentar" type="xsd:string"/>
<xsd:complexType name="BestellungTyp">
<xsd:sequence>
<xsd:element name="Lieferadresse" type="DeAdresse"/>
<xsd:element name="Rechnungsadresse" type="DeAdresse"/>
<xsd:element ref="Kommentar" minOccurs="0"/>
<xsd:element name="Waren" type="WarenTyp"/>
</xsd:sequence>
<xsd:attribute name="bestelldatum" type="xsd:date"/>
</xsd:complexType>
WI
<xsd:complexType name="WarenTyp">
<xsd:sequence>
<xsd:element name="Buch" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Titel" type="xsd:string"/>
<xsd:element name="Anzahl">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="PreisEUR" type="xsd:decimal"/>
<xsd:element ref="Kommentar" minOccurs="0"/>
<xsd:element name="Lieferdatum" type="xsd:date"
minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="ISBN" type="ISBNTyp" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DeAdresse">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="Straße" type="xsd:string"/>
<xsd:element name="Ort" type="xsd:string"/>
<xsd:element name="PLZ" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute
name="land"
type="xsd:NMTOKEN"
fixed="DE"/>
Vorlesung
"Daten-,
Informationsund Wissensmanagement"
(MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
http://www.heise.de/ix/artikel/Schnelle-Tabelle-506390.html
</xsd:complexType>
32
Beispielschema: Buchbesprechung (ii)
<xsd:simpleType name="ISBNTyp">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{9}[0-9X]"/>
<!-- 9 Ziffern gefolgt von einer Prüfziffer im Bereich zwischen 0 und 10
(10 wird als X dargestellt) -->
</xsd:restriction>
</xsd:simpleType>
ISBN-Nummern
</xsd:schema>
Die Prüfziffer (zehnte Ziffer) der ISBN-Nummer berechnet sich wie folgt:
Man multipliziere die erste Ziffer mit eins, die zweite mit zwei, die dritte mit drei und so fort bis zur neunten Ziffer, die mit neun multipliziert wird.
Man addiere die Produkte und teile die Summe ganzzahlig mit Rest durch 11. Der Divisionsrest ist die Prüfziffer. Falls der Rest 10 beträgt, ist die Prüf-"ziffer" ein "X".
1. Beispiel: ISBN 3-499-13599-[?] (Fräulein Smillas Gespür für Schnee)
3·1 + 4·2 + 9·3 + 9·4 + 1·5 + 3·6 + 5·7 + 9·8 + 9·9 = 3 + 8 + 27 + 36 + 5 + 18 + 35 + 72 + 81 = 285
285:11 = 25 Rest 10 ⇒ Prüfziffer: X
2. Beispiel: ISBN 3-446-19313-[?] (Fermats letzter Satz)
3·1 + 4·2 + 4·3 + 6·4 + 1·5 + 9·6 + 3·7 + 1·8 + 3·9 = 3 + 8 + 12 + 24 + 5 + 54 + 21 + 8 + 27 = 162
162:11 = 14 Rest 8 ⇒ Prüfziffer: 8
3. Beispiel: ISBN 0-7475-5100-[?] (Harry Potter and the Order of the Phoenix)
0·1 + 7·2 + 4·3 + 7·4 + 5·5 + 5·6 + 1·7 + 0·8 + 0·9 = 14 + 12 + 28 + 25 + 30 + 7 = 116
116:11 = 10 Rest 6 ⇒ Prüfziffer: 6
4. Beispiel: ISBN 1-57231-422-[?] (Hardcore Visual Basic)
1·1 + 5·2 + 7·3 + 2·4 + 3·5 + 1·6 + 4·7 + 2·8 + 2·9 = 1 + 10 + 21 + 8 + 15 + 6 + 28 + 16 + 18 = 123
123:11 = 11 Rest 2 ⇒ Prüfziffer: 2
hier aus http://www.arndt-bruenner.de/mathe/scripts/pruefziffern.htm
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
33
XML Datei mit eingebauter Referenz auf Schema
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:schemaLocation="http://www.w3schools.com
note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
34
Agenda
• XLML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
35
Dokumentenbaum und Navigation (XPATH)
XPath
• “a declarative language for locating nodes and fragments in XML trees “
• “used in both XPointer (for addressing), XSL (for pattern matching), XML Schema (for
uniqueness and scope descriptions), and XQuery (for selection and iteration)”
• http://www.zvon.org/comp/r/ref-XPath_2.html ausführliche Referenz
• http://dret.net/lectures/xml-fall06/xpath weitere Literatur
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
36
XQuery versus SQL
How XQuery differs from SQL
Many SQL users mistakenly assume that XQuery is very similar to SQL. However, XQuery differs from SQL in many ways
largely because the languages were designed to work with different data models that have different characteristics. XML documents contain
hierarchies and possess an inherent order. By contrast, tables supported by relational DBMSs (or, more precisely, SQL-based DBMSs) are flat
and set-based, so rows are unordered.
These differences in data models result in significant differences in the query languages designed to support each of them. For
example, XQuery lets programmers navigate through XML's hierarchical structure. Plain SQL (without XML extensions) does not have -- or
need -- equivalent expressions to "navigate" through tabular data structures. XQuery supports both typed and untyped data, while SQL data is
always defined with a specific type. XQuery lacks null values because XML documents omit missing or unknown data. SQL uses nulls to
represent missing or unknown data values. XQuery returns sequences of XML data; SQL returns result sets of various SQL data types.
Finally, XQuery operates only on XML data. SQL operates on columns defined on traditional SQL types, and SQL/XML (SQL with
XML extensions) operates on both XML data and traditional types of SQL data.
Quelle: http://www.ibm.com/developerworks/data/tutorials/db2-cert7307/section2.html
These are just a few of the differences between XQuery and SQL. It is beyond the scope of this introductory tutorial to provide an exhaustive list, but Resources has more on this topic.
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
37
Relevanz von XPATH
•
•
XML structures data into a rather small number of different constructs, most notably elements and
attributes. The XML Path Language (XPath) defines a way how to select parts of XML documents, so
that they can be used for further processing. XPath's primary use in in XSL Transformations (XSLT),
but other XML technologies use it as well, e.g. XML Schema.
XPath is a very compact language with a syntax that resembles the path expressions which are wellknown from file systems. These path expressions, however, are generalized and therefore much
more powerful than the rather simple path expressions in file systems. Because of its use in
different XML technologies, XPath is one of the most important XML core technologies.
Quelle: http://dret.net/lectures/xml-fall06/xpath
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
38
XPATH document tree
Hinweise:
•Die Validierung gegen ein Schema etc. ist bereits
erfolgt, ehe der Baum aufgebaut ist
•Alle <[CDATA[ ]]> etc. sind bereits aufgelöst
•Jeder Knoten hat einen zughörigen Attributknoten
•Unter <street> liegt ein Textknoten mit dem Text-Wert
•In Datenbanken (wo viele XML-Dokumente
aufeinanderfolgen gibt es einen übergeordneten
document(DBfilePath) Knoten
(partially from http://www.ibm.com/developerworks/data/tutorials/db2-cert7307/section2.html)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
39
XPATH Navigationsbefehle (1)
(partially from http://www.ibm.com/developerworks/data/tutorials/db2-cert7307/section2.html)
Beispiele zu obigem Dokument
•
•
•
•
•
•
•
/Client/email
/Client/email[1]
/Client[@id='123']/email[1]
/Client/Address[state="CA"]/zip
/Client/*/city
/Client/Address/city
/Client//city
XPATH adressiert immer Knoten
/ und Knotenname navigiert nach unten
// mit beliebig vielen Ebenen dazwischen
[ ] setzt Bedingungen am aktuellen Knoten, sog.
„predicates“
@ referenziert dessen Attribute (die eigentlich
immer einen eigenen Knoten haben)
WI
•
•
•
•
•
•
//* (Retrieves all nodes in the document)
//email (Finds email elements anywhere in
the document)
/Client/email[1]/text() (Retrieves the text
node of the first email element beneath the
Client element)
/Client/Address/* (Selects all child nodes of
the Address sub-element of root Client
element)
/Client/data(@id) (Returns the value of the id
attribute of the Client element)
/Client/Address[state="CA"]/../email (Finds
the email elements of clients with an
address in California. The ".." step navigates
back to the parent of the Address node.)
state is a child node !
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
40
Hinweis zu gemischten Knoten
jeder Knoten hat (implizit) einen TextValue aus der String-Verkettung aller Einträge ohne die inneren tags:
<König>Friedrich II <Beiname bemerkung=„sogenannt“>der Große </Beiname> von Preußen
<qualität einschaetzung=„echter Preusse“ /> </König>
•
•
•
generiert 1 Knoten „König“ mit 2 direkten (und 1 indirekten) Textknoten
1 Attributknoten zu „König“ ist leer
Beiname Knoten hat Attributknoten mit „bemerkung“
•
der „Textvalue“ des Königsknotens wäre die Friedrich II der Große von Preußen
(siehe weiter unten für Wiederaufnahme diese Themas)
/könig/text() hätte als Wert die Sequenz (Friedrich II , der Große ,von Preußen)
•
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
41
XPATH: Naviagtion entlang Achsen („axes“)
•
•
•
Bisher: „nächster Knoten nach Name“ (via / ) oder „Elter“ (via /../ )
Aber auch: „nächstes Geschwister“ oder „nächstes Geschwister, das Text-Knoten ist“
 das heißt: brauchen Navigationsrichtung („axis“) und (meist) Bedingungen („alle Kinder, vom Typ book, wobei
‚book‘ ein attribut namens ‚size‘ hat“)
•
www.tei-c.org/Talks/OUCS/2006-02/talk-xpath.pdf sehr schöne Einführung zum Durcharbeiten !!!
•
http://www.devarticles.com/c/a/XML/Introduction-to-XPath/
–
•
http://www.quackit.com/xml/tutorial/xpath_introduction.cfm
–
WI
mit bsp und Programmierspracheneinbindung
etwas systematischer
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
41
Quelle: http://krum.rz.uni-mannheim.de/inet-2003/images/xpath-axis.gif
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
42
XPATH: Navigation entlang Achsen („axes“)
NOTATION achsenname::TestOderAuswahlbedingung [ggf.zusätzliche Werttests]
•
•
•
•
•
•
•
•
•
•
child::book Selects all book nodes that are children of the current node
attribute::lang Selects the lang attribute of the current node
child::* Selects all children of the current node
attribute::* Selects all attributes of the current node
child::text() Selects all text child nodes of the current node
child::node() Selects all child nodes of the current node
descendant::book Selects all book descendants of the current node
ancestor::book Selects all book ancestors of the current node
ancestor-or-self::book Selects all book ancestors of the current node - and the current as well if it is a book node
child::*/child::price Selects all price grandchildren of the current node
Hinweis: Wenn mehr als ein Knoten ausgewählt wird, dann geben alle Knoten eine “sequence” [ab xpath 2.0)
(de facto: lineare Liste)
The formal specification of an XML Path is very complex, i.e. has about 39 clauses and is very difficult to understand
Some expressions shown here are beyond the scope of this tutorial, don't panic !
(from http://edutechwiki.unige.ch/en/XPath_tutorial_-_basics)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
43
Aus dem hervorragenden http://oreilly.com/perl/excerpts/system-admin-withperl/ten-minute-xpath-utorial.html
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
44
<network>
<description name="Boston">
This is the configuration of our network in the
Boston office.
</description>
<host name="agatha" type="server" os="linux">
<interface name="eth0" type="Ethernet">
<arec>agatha.example.edu</arec>
<cname>mail.example.edu</cname>
<addr>192.168.0.4</addr>
</interface>
<service>SMTP</service>
<service>POP3</service>
<service>IMAP4</service>
</host>
<host name="gil" type="server" os="linux">
<interface name="eth0" type="Ethernet">
<arec>gil.example.edu</arec>
<cname>www.example.edu</cname>
<addr>192.168.0.5</addr>
</interface>
WI
<service>HTTP</service>
<service>HTTPS</service>
</host>
<host name="baron" type="server"
os="linux">
<interface name="eth0"
type="Ethernet">
<arec>baron.example.edu</arec>
<cname>dns.example.edu</cname>
<cname>ntp.example.edu</cname>
<cname>ldap.example.edu</cname>
<addr>192.168.0.6</addr>
</interface>
<interface name="en1" type="AirPort">
<arec>zeetha.wireless.example.edu</are
c>
<addr>192.168.100.101</addr>
</interface>
</host>
</network>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
45
Aus dem hervorragenden
oreilly.com/perl/excerpts/system-admin-with-perl/ten-minute-xpath-utorial.html
Einfaches Beispiel
•
/network/host[2]/service[1]/text() 
•
/child::network/child::host[position()=2]/child::service[position()=1]/
child::text()
Komplexes Beispiel
If we wanted to write a location path that tried to find all of the hosts with multiple interfaces, we could write
/child::network/child::host/child::interface[position()=1]/following-sibling::interface/parent::host/attribute::name
This essentially says, “Walk down from the network node until you find a host with an interface node as its child, then see if it has a sibling interface at
the same level in the tree. If it does, walk back up to the host node and return its name attribute.”
NB: a failed match simply skips to next occurrence
Erweiterung und Variante (JR)
/child::network/child::host/attribute::name gibt alle hostnamen während wir auf host sitzen, können wir dessen interfaces auf ≥ 2 prüfen
/child::network/child::host [count(child::interface)>1]/attribute::name
/network/host[count(interface)>1]/@name
count ist wie position eine xpath function (zB https://developer.mozilla.org/en-US/docs/Web/XPath/Functions für
komplette Liste)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
46
File System versus XPath Adressierung
File system paths geben immer genau 1 directory oder file

XPATH statements geben ggf. eine ganze („flattened“) Liste von
Knoten (d.h. alle Knoten hintereinander in einer 1-dim Liste)
http://dret.net/lectures/xml-fall06/xpath#%2816%29
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
47
Beispiel der Umsetzung des Eingangsbeispiels
Ein <Land> zum <Hobby> eines
in XML
<Freunds>
<Kontakte>
<Freund> <Name> Meier</Name>
<Hobby> BriefmarkenSammeln <Land> Deutschland </Land> <Land>Liechtenstein </Land> <Land> Indien</Land>
<Thema> Blumen </Thema><Thema>Schach</Thema>
</Hobby> </Freund>
<Freund> <Name> Meyer </Name>
<Hobby> BriefmarkenSammeln <Land> Deutschland </Land>
<JahrgangVon> 1900
</JahrgangVon> <JahrgangBis> 1945 </JahrgangBis> </Hobby> </Freund>
<Geschäftscontact> <Name> Meyer </Name> <Adresse>blabla </Adresse>
<Hobby> BriefmarkenSammeln <Land> Deutschland </Land> <Bis> 1945 </JahrgangBis> </Hobby>
</Geschäftscontact>
<Freund> <Name> Huber <Spitzname> Jojo </Spitzname></Name>
<Hobby> Schach <Niveau> Meister </Niveau> <Eroeffnung> Pirc </Eroeffnung> <Eroeffnung> Orang-Utan
</Eroeffnung> </Hobby> </Freund>
<Freund> <Name> Schmidt </Name>
<Hobby> Schach <Niveau> Großmeister </Niveau>
<Eroeffnung> Italienisch</Eroeffnung>
<Eroeffnung> Nimzo-Indisch </Eroeffnung> <Hobby> </Freund>
<Freund> <Name> Huber </Name> <Name> der wo schwimmt wia a Fisch </Name>
<Hobby> Tiefseetauchen
<TauchtiefeVon unit=„m“> 20 </TauchtiefeVon>
<TauchtiefeBis unit= „m“> 100 </TauchtiefeBis> <Meere> Indischer Ozean, Karibik </Meere> </Hobby>
<Hobby> Schach <Niveau> Anfänger </Niveau> </Hobby> </Freund>
</Kontakte>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
48
Abfragebeispiel
Namen der Freunde, die mindestens 50m tief tauchen
Eine Strategie:
• Prüfe „Tauchtiefe bis“
• Und dann ggf. nach oben im Baum, um den Namen zu erhalten
/Kontakte/Freund/Hobby[TauchtiefeBis > 50]/../Name[1]
-- falls auch
Spitznamen mit angegeben; > ist das > Zeichen zur Sicherheit in Ersatzdarstellung; > ist meist OK
•
Vielleicht besser: zunächst den gesamten Knoten für einen Freund, der über 50m taucht
… und dann der „Namen“ Subknoten
/Kontakte/Freund[Hobby/TauchtiefeBis > 50 AND
Hobby/TauchtiefeBis[@unit = “m“ ] ] /Name[1]
Zu den ANDs und „predicates can be nested“ siehe auch
http://commons.oreilly.com/wiki/index.php/XPath_and_XPointer/Location_Steps_and_Paths
weiterführender Hinweis TauchtiefeBis > 50 sucht vom KNOTEN Tauchtiefe zunächst dessen textvalue und wandelt
diesen dann wegen > in eine Zahl
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
49
(zur Vertiefung) Erweiterungen
•
Rechnen Joins etc. im XPath
–
–
•
•
XPATH 1.0 cheatsheet
http://dret.net/lectures/xml-fall06/xpath-quickref.pdf
XPath adressiert Knoten
–
–
–
–
WI
http://www.xml.com/pub/a/2002/03/20/xpath2.html?page=2
Sum etc.: http://www.iro.umontreal.ca/~lapalme/ForestInsteadOfTheTrees/HTML/ch04s03.html
der Wert ist wieder ein Dokument mit diesem Knoten als root
der string-value eines jeden Knoten ist die Verkettung aller text-Unterknoten in document order (zu
den feinen Details siehe das gute
http://dret.net/lectures/xml-fall06/xpath-chapter.pdf
http://dret.net/lectures/xml-fall13/xpath20 § (Stanford))
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
50
<<erweiternd>> aus
http://www.iro.umontreal.ca/~lapalme/ForestInsteadOf
TheTrees/HTML/ch04s03.html
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
52
XPOINTER und XLINK
(Verweise im Hyperlink)
Probleme (Auswahl):
Ein Hyperlink sollte nicht nur auf einen Textknoten verweisen,
sondern
•
Auf genau einen Buchstaben innerhalb des Textknotens
•
Auf einen Bereich, der eine ID trägt
•
Auf Bereiche von .. bis
 XPOINTER erweitert die Möglichkeiten von XPATH
•
Example:
•
/descendant::text()/point()[position()=0] den Textknoten
des Abkömmlings; davon den Punkt mit der positionEigenschaft, insgesamt also ist jetzt (eine Liste von)
Pointern unmittelbar vor dem Beginn der Texte
•
 selects the locations right before the first character
of all character data nodes in the document.
•
•
•
•
•
•
A point can represent the location preceding or
following any individual character in e.g. chardata nodes.
The special node test point()
selects the set of points of a node
In aller Regel werden wir nur einige Punkte auswählen.
A range consists of two points in the same document,
and is specified using a special range-to location step
construct.
Example:
/section[1] / range-to(/section[3])
daneben Navigation zu einen Knoten mit einer id weit
verbreitet
Siehe z.B.: www.brics.dk/~amoeller/XML/linking/extra.html
Und www.fh-wedel.de/~si/seminare/ws00/Ausarbeitung/3.xlink/xlink6.htm
http://slideplayer.org/slide/660348/
http://commons.oreilly.com/wiki/index.php/XPath_and_XPointer/XPointer_Syntax
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
51
Erweiterung (abseits des Stoffs)
referentielle Integrität im XPATH überprüfen :
siehe zB
www2.informatik.hu-berlin.de/~obecker/Lehre/SS2002/XML/11c-schema.html
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
52
Agenda
• XLML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
53
XQuery: Abfrage von XML-Datenbeständen
• http://www.stylusstudio.com/xquery_primer.html einstieg
Sehr gute Intro http://dbs.uni-leipzig.de/file/dbs2-ss10-kap6.pdf !!!!
http://lots.uni-leipzig.de/xqtrain/index.jsp trainer dazu
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
54
FLWR ForLetWhereReturn
4 Elemente einer Query
•
for aVariable in aSequence
for $a in //teilelement
 nacheinander wird das folgende für $a = erstes passendes Teilelement, zweites passendes … ausgeführt
•
let aVariable = aSequence
let $a = // teilelement
 $a steht für die Liste (Sequenz) aller zutreffenden Teilelemente; die Variable $a kann mit den in der Sprache
vorgesehenen Funktionen für Sequenzen später weiterberbeitet werden
•
where  Bedingungen
where /name/nachname = ‘Ruhland‘
•
•
return  welcher Wert (i.d.R. wieder XML) wird zurückgeliefert
order by wie üblich
Im folgenden nur For und Return
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
55
FLWR in einfachen Beispielen
<customers>
•
{
•
for $c in
document("data/customers.xml")//customer
return
$c/email
}
</customers>
XML customers.xml siehe Folgefolien
Files auf dem Laufwerk!
The query result looks like this:
<customers>
<email>[email protected]</email>
<email>[email protected]</email>
<email>[email protected]</email>
<email>[email protected]</email>
</customers>
Lies:
schneide der Reihe nach einzeln (FOR!) die
//customer Teilbäume des Documents heraus
Jeder Teilbaum heißt $c
Und mit diesem $c-Baum kannst du
 jetzt jedes XPATH machen
Keine <email> bei Armanda Johnson
Georgi hat <email>, ist aber kein <customer>
Adapted from http://www.devx.com/xml/Article/8066/1954
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
56
FLWR in einfachen Beispielen (Verbesserung) mit besserem Ergebnis
<customers>
{
for $c in document("data/customers.xml")//customer
return
<customer> {$c/email} </customer>
}
</customers>
The query result looks like this:
<customers>
<customer> <email>[email protected]</email> </customer>
<customer> <email>[email protected]</email>
<email>[email protected]</email> </customer>
<customer> </customer> --- von Armanda
<customer> <email>[email protected]</email> </customer>
</customers>
<contact> Georgi generiert keinen Output, da er schon das FOR nicht matched
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
57
Beispieldatei hierzu: customer.xml
<?xml version="1.0" encoding="UTF-8" ?>
<ixq:customers
Erste
xmlns:ixq="http://www.ipedo.com/XQueryExample">
Instantiierung
<customer>
von $c ist dieser
<custno>9000</custno>
Baum
<name>
<firstname>Joe</firstname>
<lastname>Anderson</lastname>
</name>
<email>[email protected]</email>
<phone>1-888-555-1234</phone>
</customer>
<customer>
<custno>1001</custno>
<name>
<firstname>Andy</firstname>
<lastname>Shaperd</lastname>
</name>
<email>[email protected]
</email>
WI
<email>[email protected]</email>
</customer>
- <customer>
<custno>1003</custno>
- <name>
<firstname>Amanda</firstname>
<lastname>Johnson</lastname>
</name>
</customer>
<contact> <firstname> Georgi</firstname>
<email>[email protected] </email></contact>
- <customer>
<custno>2005</custno>
- <name>
<firstname>Bill</firstname>
<lastname>Murphy</lastname>
</name>
<email>[email protected]</email>
</customer>
</ixq:customers>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
58
FLWR
LET (mit collection)
•
let $c :=
document("data/customers.xml")//custo
mer/custno
FOR (mit Einzelwerten)
for $c in
document("data/customers.xml")//customer
/custno
return <customers> {$c} </customers>
return <customers> {$c} </customers>
•
<customers> <custno>9000</custno>
<custno>1001</custno>
<custno>1003</custno>
<custno>2005</custno> </customers>
Die curly brackets fordern eine Auswertung
der Variablen $c an; sonst wird nur der Text
$c ausgegeben
WI
•
•
•
•
<customers> <custno>9000</custno>
</customers>
<customers> <custno>1001</custno>
</customers>
<customers> <custno>1003</custno>
</customers>
<customers> <custno>2005</custno>
</customers>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
59
Ein komplexes Beispiel „outer join“ in XQUERY
•
•
•
An outer join is a join that preserves information from one or more of the participating documents, including
elements that have no matching element in the other documents. Consider the following query, which lists all
customers as well as the purchase order id for those customers who have placed orders.
# see XQuery36.ixq in samples.zip
for $u in document("data/customers.xml")//customer
return <customer id={$u/custno}> <name>{$u//firstname/text()}
{$u//lastname/text()}</name>
{ for $p in document("data/PO.xml")//po where $u/custno = $p//custno return
<po id= {$p/@id} / > } }
{} erzwingen Auswertung
Text() lässt (in gewisser
</customer>
Näherung)die <tags> weg
The query returns the following result: <customer id="9000"> <name> Joe Anderson </name> <po id="0001"/>
</customer> <customer id="1001"> <name> Andy Shaperd </name> <po id="0002"/> </customer> <customer
id="1003"> <name> Amanda Johnson </name> </customer> <customer id="2005"> <name> Bill Murphy </name>
</customer>
You can see that the query result lists all the customers, regardless of whether or not they have placed a PO.
Conventionally, a join that selects all the items from the left side of the join is called a left outer join.
http://www.devx.com/xml/Article/8066/1954
Achtung: Fehler in der OriginalQuelle
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
60
• Die XPATH statements innerhalb des for und
let nehmen schon eine Vorselektion vor
• streng genommen ist sogar ein for … in
schon Bestandteil von XPATH 2.0
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
61
Tauchende Freunde
Name und Lieblingsmeere der über 50 m tief tauchenden
for $f in /Kontakte/Freund
where $f/Hobby/TauchtiefeBis > 50
Return {$f/Name} {$f/Hobby/Meere}
Viel Besser ist 
<allTauchende>
{for $f in /Kontakte/Freund
where $f/Hobby/TauchtiefeBis[@unit =m] > 50
return
<Tauchfreund> <Name> {$f/Name } </Name>
<Lieblingsmeere>
{$f/Hobby [text()[1] = “Tiefseetauchen“ ] ‡ /Meere}
</Lieblingsmeere>
<Tauchfreund>}
‡ um Flachseetaucher auszuschließen
</allTauchende>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
62
Bedeutende Detailfrage zur Behandlung von Textknoten
siehe https://www.progress.com/docs/default-source/default-document-library/DataDirect/Documents/Data-Integration-Suite/xquery-tips-tricks.pdf
What are the drawbacks of using /text() when it is not needed? It turns out that there are several:
•
let $doc := <root><val>foo<!-- comment -->bar</val></root>
•
return
•
($doc//val = "foobar",
•
$doc//val/text() = "foobar")
•
It returns (true, false) because the result of $doc//val/text() is actually the sequence (“foo”, “bar”) and not
“foobar” as you would expect.
Denn der Wert eines Knotens ist der String value einschließlich aller eingeschlossenen Knoten ex die Tags, so wie er vorkommt. Mit text()
schauen wir in die Unterknoten und haben eine Liste der Text-Unterknoten
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
63
Agenda
• XLML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
64
SQL und XQuery gemischt
Typische Lösungen (IBM DB2) (hier aus
www.ibm.com/developerworks/data/library/techarticle/dm-0603saracco2)
aber ein SQL Standard existiert
siehe etwa: dbs.uni-leipzig.de/file/dbs2-ss10-kap6.pdf
• XML ist ein Column-Type im SQL
• Richte XQUERY der Reihe nach gegen alle XML-Dokumente, die ein SQL-Befehl
abliefert
• Und/oder mische die XQUERY und SQL-Operationen über Funktionen wie
XMLEXISTS (siehe unten)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
65
SQL und XQuery gemischt
Beispiel-Dokumente
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
66
SQL und XQUERY (ii)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
67
SQL und XQUERY (iii)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
68
Agenda
• XLML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
69
α XHTML als „strenge“ Variante von HTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Strict DTD XHTML Example </title>
</head>
<body>
<p>
Please Choose a Day:
<br /><br />
<select name="day">
<option selected="selected">Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
</select>
</p>
</body>
</html>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
70
β XSL-FO  Beispiel einer Anwendung zur Verarbeitung von XML Dokumenten
• XSL-FO (Extensible Stylesheet Language – Formatting Objects) ist eine XMLAnwendung, die beschreibt, wie Text, Bilder, Linien und andere grafische
Elemente auf einer Seite angeordnet werden. Mit Hilfe von XSL-FO ist es
möglich, qualitativ hochwertige Druckerzeugnisse entweder auf Papier oder auf
dem Bildschirm zu erzeugen. Die Spezifikation erlaubt sogar, dass XSL-FODokumente beispielsweise über einen Sprachsynthesizer vorgelesen werden
können. (Wikipedia)
• Ein XSL-FO-Dokument enthält den Text und Formatierungsinformation
• … es kann aus einem reinen Text-Dokument in einem ersten Schritt hergestellt
werden (mit einem „beliebigen“ Programm)
• http://code.google.com/p/fop-miniscribus/
• http://www.ibm.com/developerworks/xml/tutorials/x-cert2/section4.html
gutes Tutorial
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
71
•
The XSL-FO example illustrated later in
this section will use XSLT to perform the
transformation, and then Apache's open
source Formatting Objects Processor (FOP)
to format the XSL-FO file to PDF
format. (ibd.)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
72
Möglichkeiten und Beispiel
•
•
•
•
•
Unterschiedliches Layout für verschiedene Seiten (Titel,
gerade und ungerade Seiten, …)
Headers, Footers, Footnotes
Listen, Tabellen
Containers
…
Limited capabilities - XSL-FO was specifically designed to meet
the requirements of "lightly designed" documents typified
by technical manuals, business documents, invoices, and so
on. While it can be and is used for more sophisticated
designs, it is inherently limited in what it can do from a
layout and typographic perspective
(from http://en.wikipedia.org/wiki/XSL_Formatting_Objects)
•
WI
http://www2.informatik.huberlin.de/~obecker/Lehre/SS2002/XML/08a-xslfo.html
sehr schöne Intro !!!
<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>Hello, world!</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
73
http://xmlgraphics.apache.org/fop/
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
74
γ UBL Universal Business Language als Anwendung
Grundideen
• Ein System von Dokumenten im zwischenbetrieblichen Austausch so
standardisieren, dass die 80/20 Regel zweifach eingehalten wird:
– Nur die wichtigsten Dokumente (Rechnung, Bestellung, …)
– Innerhalb der Dokumente die allgemein bedeutenden Felder; die
Geschäftspartner sollen (einfach und doch standardisiert) zusätzliche
Informationen austauschen können
• Dokumente werden im Rahmen von zwischenbetrieblichen
Geschäftsprozessen ausgetauscht. Diese müssen immer abgestimmt
werden (sog. „Choreographie“). Auch dieser Abstimmungsprozess muss
standardisiert sein  „Business Scenarios“ definiert
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
75
Beispiel eines Szenarios
Einkauf
Nutzer
Aus www.teialehrbuch.de/Kostenlose-Kurse/XML/7899-Dokumenttypen-fuer-Geschaeftsprozesse-UBL-als-Beispiel.html
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
76
UBL Universal Business Language als Anwendung
•
Vorteile XML
– Mittels eines Haupt-Schemas in XSL-Art kann eine Standardisierung pro
Dokumententyp erreicht werden. Ein derartiges Schema kann an definierten Stellen
das Einstellen der benutzerspezifischen Werte gestatten
– Mittels des Schemas und Validierungssoftware kann die Gültigkeit geprüft werden,
ohne dass man Hard- oder Software vorschreiben müsste
• Vgl http://www.oioubl.info/validator/default.aspx
•
„sanfter Zwang“
– Aufgrund deutlicher (interner) Rationalisierungsvorteile nehmen Regierungen (hier Dk,
teils S und E) nur noch Rechnungen an, die entsprechend gestaltet sind
– Siehe http://www.oioubl.info/
– „FormatierungsSW“ (XML  Ausdruck) extrem günstig verfügbar
Zu den Vorteilen siehe http://ubl.xml.org/wiki/why-use-ubl
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
77
UBL 2.0 Dokumente
aus http://www.unimaze.com/on+ubl.aspx
„catalog“ ist im Sinne des e-commerce zu verstehen
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
78
UBL 2.0 „in Aktion“
• http://www.schemacentral.com/sc/ubl20/tns19_InvoiceType.html für die Rechnung und link zum Schema
http://www.schemacentral.com/sc/ubl20/e-ns19_Invoice.html
• Software http://www.simpleubl.com/products/electronicbusiness-documents/
• Übersetzung in Print :
http://www.w3.org/XML/Binary/2005/03/test-data/UBL1.0/fs/Invoice/pdf/OfficeInvoice.Example-a4.pdf
• Rund 150 Mio. € Ersparnis p.a. in DK
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
79
δ XML in EXCEL
Anwendung 1: Excel kann XML importieren und exportieren
• http://www.bitwizards.com/Blogs/Bryan-Soltis/November-2010/How-To-Export-an-Excel2010-Worksheet-to-XML
• http://www.heise.de/ix/artikel/Schnelle-Tabelle-506390.html
http://algconsultings.wordpress.com/2010/10/24/import-data-into-excel-xml/
• Sehr schön auch www.youtube.com/watch?v=1OKZN2sUuvs creating XML from EXCEL
Anwendung 2: Gesamte EXCEL-Funktionalität (incl. Formatierung von Zellen und Formeln) kann als
XML-Datei generiert werden:
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats
http://msdn.microsoft.com/en-us/library/aa140062(office.10).aspx
Mittels XSLT kann man auch einer XML –Datei derartige Formatierung mitgeben (z.B.
http://www.openscope.net/2010/02/09/transforming-xml-into-ms-excel-xml/ )
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
80
Agenda
• XLML Datenbanken für semistrukturierte Bestände
a. Grundidee von XML, Schemata (XSD) verlangen in einstellbarem
Detail Struktur von Dokumenten
b. Adressierung im Dokumentenbaum (XPATH und Xpointer als
Grundvoraussetzungen einer Bearbeitung von Teilen des Dokuments)
c. XQUERY (und FLOWR) als Abfragesprachen des reinen XML
d. XQUERY und SQL : gemischte Verwendung
e. XML in Anwendungen (XML liefert die Datenstruktur für
Anwendungen)
f. XSLT als eine „Infrastruktur“-Anwendung
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
81
• MASTER Programm !
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
82
XSLT als eine
“Infrastruktur”-Anwendung
(ergänzend außerhalb des Stoffs)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
83
XSLT als Infrastruktur-Utility
•
•
http://www.fh-wedel.de/~si/seminare/ws00/Ausarbeitung/5.xslt/xslt0.htm
http://www.cafeconleche.org/books/bible2/chapters/ch17.html „ab initio“ (erklärt
XPATH mit) ab Listing 17-5 richtig gut
•
•
beides sehr gute Einführungen (siehe auch RESQ)
http://www.zvon.org/xxl/XSLTutorial/Output_ger/example6_ch1.html und das ganze
Tutorial ist sehr brauchbar
•
http://edutechwiki.unige.ch/en/XSLT_Tutorial_-_Basics see esp. 6.2 @2013
Hinweis: Die Fähigkeit, selbst komplexere XSLTTransformationen zu erstellen, wird im Kurs nicht erwartet
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
84
Grundsätzlicher Betrieb des XSLT-prozessors
„Templates“ „matchen“ gegen
Gesamtbaum oder Teile
daraus
… und für jedes Template sagen
wir, was zu tun ist, z.B.:
•
•
•
•
•XSLT verändert nie die Input-Datei
•Braucht (fast) immer einen XML-Input
•Kann XML oder anders formatierten Output
generieren
WI
Teile des Dokuments in den Output
kopieren
die Template Idee rekursiv anwenden
Etc (z.B. umsortieren)
Wenn nichts zur jeweiligen Wurzel „/“
nichts explizit gesagt ist, greift der
Default:
– Alle Unterknoten verarbeiten
– Alle Texte Kopieren
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
85
Einführung in XSLT-Processing (0)
Die Darstellung in der Einführung folgen dem sehr guten Kurs
http://www.w3schools.com/xsl/default.asp
zum Online Testen siehe http://www.w3schools.com/xsl/tryxslt.asp
offline Freeware xslt-tester
http://development.webbie.org.uk/xmlconverter/
online Alternativen
http://xslttest.appspot.com/
http://xslt.online-toolz.com/tools/xslt-transformation.php
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
86
Einführung in XSLT-Processing (1)
xslt Dokument beginnt immer mit
•
•
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0“ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
•
im Namespace xsl liegen die xsl-Transformationen
das xslt- Dokument ist ein wohlgeformtes XML
• ein darzustellendes xml-Dokument kann mittels
•
•
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
•
ein Darststellungs-xsl referenzieren, was alle modernen Browser dann „honorieren“, wenn sie das
Dokument darstellen wollen
als SEHR guten Einstiegskurs
siehe http://www.w3schools.com/xsl/xsl_transformation.asp
http://www.w3schools.com/xsl/xsl_examples.asp erläutert die Sprach-Elemente an ausführbaren Beispielen !!
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
87
Vorbemerkung zum Beispiel:
Rendering von HTML im Browser
<html> <body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Das Lied der Berge </td>
<td>Hansi Hinterseer</td>
</tr>
<td> Lass Di busseln </td>
<td>Wildegger Herzbuam</td>
</table> und Tschüss
</body> </html>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
88
Einführung in XSLT-Processing (2)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
und jede Menge weitere CDs; StillGotTheBlues ohne artist
</catalog>
1.
2.
3.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
<xsl:template match="/">
<html> <!-- Blau ist nacktes Kopieren; ein späteres Prog solls verstehen -->
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:if test="price > 10">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_if
in sehr gutem Detail !!!
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
89
Einführung in XSLT-Processing (3)
• vor jedem Processing  Übergang zum DOM
• templates sind REGELN
– Voraussetzung der Anwendung im match Attribut (das mit xquery
qualifiziert sein kann)
– „was zu tun“ in den Folgeteilen der Regel. Meist:
• Ausgabe eines/mehrerer (Teil)Knoten (wieder xquery-Selektion erlaubt; zeile
13 z.B. <xsl:for-each select="catalog/cd[artist]"> )
• oder Suche nach auf die Unterknoten anwendbaren Regeln (siehe Folgefolie)
durch apply-templates
– nur mit xsl:for-each werden alle geeigneten Unterknoten behandelt
– xsl:if testet Bedingungen
– mittels { } können wir den Wert z.B. eines Attributs einfügen (siehe
Folgefolie)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
90
Quelle: http://courses.ischool.berkeley.edu/i290-8/s04/lectures/3/slide23.html
• For example
•
<img src="{@base-uri}/{@src}"/>
• for the content:
•
<image-data base-uri="http://mydomain.com" src="picture.jpg"/>
• would generate:
•
WI
<img src="http://mydomain.com/picture.jpg"/>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
91
ibd.
•
You can get values of elements or attributes via xsl:value-of:
–
–
•
•
•
WI
<xsl:value-of select="person/name"/>
<xsl:value-of select="@href"/>
The select attribute can contain any XPath expression.
The value is the result of collection the text "children" of the expression.
This is really the same as the string() function being applied to the resulting node set.
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
92
Einführung in XSLT-Processing (4) Fortgeschrittene Konzepte
• Default Rule (auch schon bei /):
–
–
verarbeite alle subknoten …
greift aber NUR, wenn gar keine Regel angegeben
• rekursive Anwendung der template rules (wobei root= aktueller
Knoten; also Pfade relativ zu diesem)
• xslt und xquery haben Überlappungen. Tendenziell extrahiert
xquery aus großen Beständen, während xslt ein Dokument in ein
anderes (vergleichbar großes; lesbares ….) Dokument überführt
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
93
Hervorragende vertiefende Kurse
http://zvon.org/xxl/XSLTutorial/Output/example73_ch2.html bzw zvon.org/xxl/XSLTutorial/Output/example73_ch2.htm
Processing always starts with the template match="/" . This matches the root node (the node its only element child is the
document element, in our case "source"). Many stylesheets do not contain this element explicitly. When this template is
not explicitly given, the implicit template is used. Its sole instruction means: process all children of the current node,
including text nodes. Compare XSLT stylesheet 1 and XSLT stylesheet 2 . When a template for the node exists, there is no default processing
invoked ( XSLT stylesheet 3 ). If you want to include descendants of the node, you have to explicitly request their templates
( XSLT stylesheet 4 ).
http://www.w3.org/TR/xslt#rules mit einem bedeutenden Zitat
•
It is also possible to process elements that are not descendants of the current node. This example assumes that a
department element has group children and employee descendants. It finds an employee's department and then
processes the group children of the department.
•
<xsl:template match="employee">
<fo:block>
Employee <xsl:apply-templates select="name"/> belongs to group
<xsl:apply-templates select="ancestor::department/group"/>
</fo:block>
</xsl:template>
http://courses.ischool.berkeley.edu/i290-8/s04/lectures/
http://www.fh-wedel.de/~si/seminare/ss01/Ausarbeitung/5.xslt/xslt4.htm
http://www.quackit.com/xml/tutorial/xpath_boolean_operators.cfm
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
94
XSLT: einige Beispiele (aus www.zvon.org/xxl/XSLTutorial/Output_ger
jeweils mit Dreieck markiert)
• Unterschiedlicher Output aus dem gleichen Input (2)
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
96
Pattern matching als fundamentales Arbeitsprinzip in XSLT
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
97
Recursiver Aufruf von Templates
und hier was zum firstName
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
98
Knotenadressierung nach XPATH-Art
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
99
Knotenadressierung mit Wildcards
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
100
Attribute mitverwenden bei der Selektion
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
101
Sehr fortgeschrittene XSLT
• Templates mit Namen
• „ancestor“-Knoten im Aufruf
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
102
Ergebnis der vorherigen Folie
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
103
Programmieren in XML  Beispiel: Adobe Flex
Adobe Flex (alias:Flash) Builder. Sprache MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" backgroundGradientColors="[#000011,
#333333]">
<mx:Label text="Hello World!" verticalCenter="0" horizontalCenter="0"
fontSize="48" letterSpacing="1">
<mx:filters>
<mx:GlowFilter color="#ffffdd"/>
Hier könnten auch
</mx:filters>
Programmteile stehen
</mx:Label>
</mx:Application>
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
104
Beispiel: Adobe Flex
• Schaltelemente
<mx:VBox>
<mx:Button label="my button 1" />
<mx:Button label="my button 2" />
<mx:Button label="my button 3" />
</mx:VBox>
WI
• Programme
<mx:Script>
<![CDATA[
]]>
</mx:Script>
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
105
Kombinationsmöglichkeiten
• http://michiel.wordpress.com/2010/05/06/adventures-in-xmlland-combining-excel-xml-html-and-javascript/
WI
Vorlesung "Daten-, Informations- und Wissensmanagement" (MW31.3) | Prof. Dr. J. Ruhland | WS 2016/17
106
Herunterladen