Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
©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 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 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 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 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 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 37
Beispiele
//child::Buch[count(./Seite)<=100][count(./Seite)>=10]
//Buch[count(Seite)<=100 and count(Seite)>=10]
©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 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 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 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 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 & Honey</Track>
</Tracks>
</CD>
</CD_Sammlung>
©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"/>
…