XML Kurs 2005-8 LRZ 1
Inhalt 2005-8 LRZ 2
Werbung 1: XML steht für strukturierte Daten March 2008 2005-8 LRZ 3
Werbung 2: XML ist lizenzfrei, plattformunabhängig und gut unterstützt March 2008 2005-8 LRZ 4
Darstellung: XHTML, CSS, XSLT 2005-8 LRZ 5
Wichtige Zusammenfassungen (Buzzwords) 2005-8 LRZ 6
Definition und Beispiele <note> <to>sepp</to> <from>schorsch</from> <heading>reminder</heading> <body>achte auf trockene Füße!</body> </note> <note from="schorsch" to="sepp" type="reminder"> Achte auf trockene Füße! </note> 2005-8 LRZ 7
XML sieht ein wenig wie HTML aus March 2008 2005-8 LRZ 8
Beispiel und Motivation Mein Kofferinhalt: <table> <tr> <td>hut</td> <td>stock</td> <td>regenschirm</td> <td>brille</td> </tr> </table> 2005-8 LRZ 9
Trennung von Inhalt und Darstellung 2005-8 LRZ 10
Beispiel und Motivation <kofferinhalt> <item>hut</item> <item>stock</item> <item>regenschirm</item> <item>brille</item> </kofferinhalt> <table> <tr><apply-templates/></tr> </table> <template match="/kofferinhalt/item"> <td><value-of select="." /></td> </template> 2005-8 LRZ 11
Darstellung: XHTML, XSLT 2005-8 LRZ 12
XML überführt HTML in XHTML March 2008 2005-8 LRZ 13
XML ist neu, aber nicht so neu March 2008 2005-8 LRZ 14
Historisches 2005-8 LRZ 15
XML ist eine Familie von Techniken March 2008 2005-8 LRZ 16
XML Standard Tools 2005-8 LRZ 17
Logischer Aufbau 2005-8 LRZ 18
XML kompakt <tag> </tag> <tag/> <h1>titel</h1> <br/> <tag attname= Attribut > <tag> <a href= http://www.google.de > </a> <tag1> <tag2> </tag2> </tag1> <html> <head> </head> <body> </body> </html> 2005-8 LRZ 19
XML kompakt II <em> vs. <i> <fehler> vs. <x> <a> <b> </a> </b> 2005-8 LRZ 20
XML kompakt III <?xml version="1.0 encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1- strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>das ist der Titel</title> </head> <body> <p> Und hier ist noch jede Menge Text </p> </body> </html> 2005-8 LRZ 21
XML ist Text, aber nicht zum Lesen March 2008 2005-8 LRZ 22
XML ist modular March 2008 2005-8 LRZ 23
XML ist vom Design her ausführlich March 2008 2005-8 LRZ 24
Was sind die Vorteile bzw. Nachteile von XML gegenüber...? 2005-8 LRZ 25
XML vs CSV 2005-8 LRZ 26
XML vs CSV 2005-8 LRZ 27
Binäres XML? 2005-8 LRZ 28
XML for Streams 2005-8 LRZ 29
Umformung: Xpath 2005-8 LRZ 30
Vergleich UNIX/Windows - XML 2005-8 LRZ 31
Wie kann man Unterelemente adressieren? /geräte/pc/ip <geräte> <pc name="lxfja01.lrz.lrz-muenchen.de"> <ip>129.187.15.28</ip> <hersteller>dell</hersteller> <modell>optiplex gx620</modell> </pc> </geräte> 2005-8 LRZ 32
Xpath - Achsen./tag //tag../tag tag/* @tag 2005-8 LRZ 33
Xpath Achsen 2005-8 LRZ 34
Prädikate 2005-8 LRZ 35
Prädikate II 2005-8 LRZ 36
Beispiele //child::buch[count(./seite)<=100][count(./seite)>=10] //Buch[count(Seite)<=100 and count(seite)>=10] 2005-8 LRZ 37
Tools: perl, bash & Co. 2005-8 LRZ 38
Wichtige Zusammenfassungen (Buzzwords) 2005-8 LRZ 39
KXML-edit 2005-8 LRZ 40
Jedit 2005-8 LRZ 41
Pollo 2005-8 LRZ 42
<oxygen/> 2005-8 LRZ 43
Benchmark Problem <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffff" border="0"> <tbody> <tr> <td bgcolor="#ffffff"> <img src="images/t.gif" width="1" height="2" /> </td> <td> <img src="mapcache/protected/cu6p4-8h773-phc/radar_anim.gif" border="0"> </td> </tr> </tbody> </table> </body> </html> 2005-8 LRZ 44
XML for R x = 1:10 1 2 3 4 5 6 7 8 9 10 y = x**2 1 4 9 16 25 36 49 64 81 100 plot(x, y) 2005-8 LRZ 45
Listenverarbeitung in R sapply( 1:10, print) > 1 2 3 4 5 6 7 8 9 10 sapply( 1:10, function(x) paste( x=, x, x**2=, x**2) ) > "x= 1 x**2= 1" > "x= 2 x**2= 4" > "x= 3 x**2= 9 x = 1:10 x[3:5] > 3 4 5 2005-8 LRZ 46
XML for R # load XML functions library(xml) # get html file from URL, convert to XML, load and parse doc = htmltreeparse("http://wetter.t-online.de/radar.php", useint=t) # extract XML attribute from doc using xpath and get the 4th value img_name = sapply( doc["//img/@src"], xmlvalue)[4] # construct command for call to firefox cmd = paste("firefox http://wetter.t-online.de", img_name,sep="") system( cmd ) 2005-8 LRZ 47
XML Starlet Toolkit 2005-8 LRZ 48
XML Starlet # download html file from URL # clean html # pipe html to xmlstarlet and generate xhtml # define namespace and extract <img> tags curl http://wetter.t-online.de/radar.php tidy xml fo -H xml sel -N x="http://www.w3.org/1999/xhtml" -t -c "//x:img" xml sel -t -m "/*/*[4]" -v "./@src" 2005-8 LRZ 49
XML Starlet Toolkit 2005-8 LRZ 50
XML Starlett (xml sel t) 2005-8 LRZ 51
XML Starlet # download html file from URL # clean html # pipe html to xmlstarlet and generate xhtml # define namespace and extract <img> tags curl http://wetter.t-online.de/radar.php tidy xml fo -H xml sel -N x="http://www.w3.org/1999/xhtml" -t -c "//x:img" xml sel -t -m "/*/*[4]" -v "./@src" 2005-8 LRZ 52
XSH perl modul $scratch/>open stuff.xml parsing /home/a2815ah/stuff.xml done. />ls <?xml version='1.0' encoding='utf-8'?> <geräte>...</geräte> Found 1 node(s). />ls /* <geräte> <pc name="lxfja01.lrz.lrz-muenchen.de"> <ip>129.187.15.28</ip> <hersteller>dell</hersteller> <modell>optiplex gx620</modell> </pc> </geräte> Found 1 node(s). 2005-8 LRZ 53
XSH # download html file from URL # clean html # pipe html to xsh and extract <img> tags curl http://wetter.t-online.de/radar.php tidy xsh -O temp1.xml -p "register-namespace x 'http://www.w3.org/1999/xhtml'; ls //x:img/@src" 2005-8 LRZ 54
Datenbanken: XQuery, xmldb, exist 2005-8 LRZ 55
XQuery 2005-8 LRZ 56
Datenbanken: XQuery for $x in /geräte/pc where./hersteller= Dell order by./modell return./ip 2005-8 LRZ 57
CRUD update insert <tag> into /path for $x in /path return $x update replace /path with <tag> update delete /path 2005-8 LRZ 58
XML als Austauschformat im Web 2005-8 LRZ 59
REST 2005-8 LRZ 60
XML Database: exist 2005-8 LRZ 61
Eine einfache Web-Applikation 2005-8 LRZ 62
Wichtige Zusammenfassungen (Buzzwords) 2005-8 LRZ 63
Wichtige Zusammenfassungen (Buzzwords) 2005-8 LRZ 64
2005-8 LRZ 65
Anhang 2005-8 LRZ 66
Beispiel: CD_Sammlung.dtd <?xml version="1.0" encoding="utf-8"?> <!ELEMENT CD_Sammlung (CD)*> <!ELEMENT CD (Titel, Interpret, Tracks)> <!ELEMENT Tracks (Track)*> <!ELEMENT Titel (#PCDATA)> <!ELEMENT Interpret (#PCDATA)> <!ELEMENT Track (#PCDATA)> <!ATTLIST Track Nummer CDATA #REQUIRED > 2005-8 LRZ 67
Beispiel: CD_Sammlung.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE CD_Sammlung SYSTEM "Y:\Systag\XML\CD_Sammlung.dtd"> <CD_Sammlung> <CD> <Titel>Jazz Roots</Titel> <Interpret>Astud Gilberto</Interpret> <Tracks> <Track Nummer="1">Stans Blues</Track> <Track Nummer="2">The Girl from Ipanema</Track> </Tracks> </CD> <CD> <Titel>Cool</Titel> <Interpret>Jeff Cole</Interpret> <Tracks> <Track Nummer="1">Hannibals Revenge</Track> <Track Nummer="2">Beer in my Mug</Track> <Track Nummer="3">Milk & Honey</Track> </Tracks> </CD> </CD_Sammlung> 2005-8 LRZ 68
Beispiel: CD_Sammlung.xsd 2005-8 LRZ 69
Beispiel: CD_Sammlung.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified" attributeformdefault="unqualified"> <xs:element name="cd_sammlung"> <xs:annotation> <xs:documentation>das Rootelement der CD_Sammlung</xs:documentation> </xs:annotation> <xs:complextype> <xs:sequence maxoccurs="unbounded"> <xs:element name="cd"> <xs:complextype> type="xs:anysimpletype"/> type="xs:anysimpletype"/> <xs:sequence> <xs:element name="titel <xs:element name="interpret" 2005-8 LRZ 70