70
©2005-8 LRZ 1 XML Kurs

XML Kurs - lrz.de · ©2005-8 LRZ 4 Werbung 2: XML ist lizenzfrei, plattformunabhängig und gut unterstützt March 2008

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

©2005-8 LRZ 1

XML Kurs

©2005-8 LRZ 2

Inhalt

©2005-8 LRZ 3

Werbung 1: XML steht für strukturierteDaten

March 2008

©2005-8 LRZ 4

Werbung 2: XML ist lizenzfrei, plattformunabhängig und gut unterstützt

March 2008

©2005-8 LRZ 5

Darstellung: XHTML, CSS, XSLT

©2005-8 LRZ 6

Wichtige Zusammenfassungen(Buzzwords)

©2005-8 LRZ 7

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 8

XML sieht ein wenig wie HTML aus

March 2008

©2005-8 LRZ 9

Beispiel und Motivation

Mein Kofferinhalt:

<table>

<tr>

<td>Hut</td>

<td>Stock</td>

<td>Regenschirm</td>

<td>Brille</td>

</tr>

</table>

©2005-8 LRZ 10

Trennung von Inhalt und Darstellung

©2005-8 LRZ 11

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 12

Darstellung: XHTML, XSLT

©2005-8 LRZ 13

XML überführt HTML in XHTML

March 2008

©2005-8 LRZ 14

XML ist neu, aber nicht so neu

March 2008

©2005-8 LRZ 15

Historisches

©2005-8 LRZ 16

XML ist eine Familie von Techniken

March 2008

©2005-8 LRZ 17

XML Standard Tools

©2005-8 LRZ 18

Logischer Aufbau

•••

©2005-8 LRZ 19

XML kompakt

<tag>…</tag> <h1>Titel</h1>

<tag/> <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 20

XML kompakt II

<em> vs. <i>

<fehler> vs. <x>

<a> <b> </a> </b>

©2005-8 LRZ 21

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 22

XML ist Text, aber nicht zum Lesen

March 2008

©2005-8 LRZ 23

XML ist modular

March 2008

©2005-8 LRZ 24

XML ist vom Design her ausführlich

March 2008

©2005-8 LRZ 25

Was sind die Vorteile bzw. Nachteile von XML gegenüber ... ?

©2005-8 LRZ 26

XML vs CSV

©2005-8 LRZ 27

XML vs CSV

©2005-8 LRZ 28

Binäres XML ?

©2005-8 LRZ 29

XML for Streams

©2005-8 LRZ 30

Umformung: Xpath

©2005-8 LRZ 31

Vergleich UNIX/Windows - XML

©2005-8 LRZ 32

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 33

Xpath - Achsen

./tag

//tag

../tag

tag/*

@tag

©2005-8 LRZ 34

Xpath Achsen

©2005-8 LRZ 35

Prädikate

©2005-8 LRZ 36

Prädikate II

©2005-8 LRZ 37

Beispiele

//child::Buch[count(./Seite)<=100][count(./Seite)>=10]

//Buch[count(Seite)<=100 and count(Seite)>=10]

©2005-8 LRZ 38

Tools: perl, bash & Co.

©2005-8 LRZ 39

Wichtige Zusammenfassungen(Buzzwords)

©2005-8 LRZ 40

KXML-edit

©2005-8 LRZ 41

Jedit

©2005-8 LRZ 42

Pollo

©2005-8 LRZ 43

<oXygen/>

©2005-8 LRZ 44

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 45

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 46

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 47

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 48

XML Starlet Toolkit

©2005-8 LRZ 49

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 50

XML Starlet Toolkit

©2005-8 LRZ 51

XML Starlett (xml sel –t)

©2005-8 LRZ 52

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 53

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 54

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 55

Datenbanken: XQuery, xmldb, eXist

©2005-8 LRZ 56

XQuery

©2005-8 LRZ 57

Datenbanken: XQuery

for $x in /geräte/pc

where ./hersteller=“Dell“

order by ./modell

return ./ip

©2005-8 LRZ 58

CRUD

update insert <tag> into /path

for $x in /path return $x

update replace /path with <tag>

update delete /path

©2005-8 LRZ 59

XML als Austauschformat im Web

©2005-8 LRZ 60

REST

©2005-8 LRZ 61

XML Database: eXist

©2005-8 LRZ 62

Eine einfache Web-Applikation

©2005-8 LRZ 63

Wichtige Zusammenfassungen(Buzzwords)

©2005-8 LRZ 64

Wichtige Zusammenfassungen(Buzzwords)

©2005-8 LRZ 65

©2005-8 LRZ 66

Anhang

©2005-8 LRZ 67

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 68

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 &amp; Honey</Track>

</Tracks>

</CD>

</CD_Sammlung>

©2005-8 LRZ 69

Beispiel: CD_Sammlung.xsd

©2005-8 LRZ 70

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>

<xs:sequence>

<xs:element name="Titel“

type="xs:anySimpleType"/>

<xs:element name="Interpret"

type="xs:anySimpleType"/>