XML und Java -- wohin geht die Reise?

Werbung
XML und Java -- wohin geht die Reise?
Mario Jeckle
DaimlerChrysler Forschungszentrum Ulm
[email protected]
[email protected]
www.jeckle.de
Research and Technology
Gliederung
I XML und Programmiersprachen ...
• Was ist die XML heute?
• Aktuelle Entwicklungen des XML-Umfeldes
II Stand der XML-Technologie ...
• XML-Schema
• SOAP/XMLP
• Ausblick: Semantic Web
III XML und Java ...
• ... eigentlich nichts Neues
• J2SE v1.4 Merlin
• XMLPack
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
2
Research and Technology
XML und Programmiersprachen ...
Java ist ...
•Programmiersprache
•Laufzeitumgebung
•Enterprise Application Platform (J2EE)
XML ist ...
•Informations- und Datenformat
•Metasprache zur Definition eigener Vokabulare
... keine:
•Programmiersprache
•Ausführungsumgebung
M. Jeckle – XML und Java -- wohin geht die Reise?
¹+
=
2001-06-28
3
Research and Technology
Stand der XML-Technologie: Web Historie
Web-Prähistorie
1. Generation
2. Generation
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
part 2
XML
Mod. XHTML using XSD
...
XSD
XPath v2
part 1
XHTML v1.0 Namensräume
HTML ...
XML Query
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
XSD
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
4
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
JavaML
(Java in XML-Syntax)
2. Generation
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
5
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
2. Generation
part 1
...
XHTML v1.0 Namensräume
HTML ...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
XSD
XPath v2
XML Query
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
Vergleichbar klassischen Scopes/C++ namespaces
zur Vermeidung von Namenskollisionen
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
6
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
2. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
XSLT v2
Referenzierungssyntax und -Semantik
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
7
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
Turing-vollständige
funktionale Programmiersprache
2. Generation
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
8
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
Vokabular zur Beschreibung
von Datendefinitionen
2. Generation
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
9
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
2. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XSLT v2
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
Algebraische Anfragesprache
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
10
Research and Technology
Stand der XML-Technologie: Programmiersprachliches an XML
Web-Prähistorie
1. Generation
2. Generation
...
1990
XML v1.0
1995
M. Jeckle – XML und Java -- wohin geht die Reise?
2000
XSD
part 2
XML
Mod. XHTML using XSD
part 1
XPath v2
XSD
XHTML v1.0 Namensräume
HTML ...
XML Query
XML Metadata Interchange
XSL-FO und XSLT
XLink, XPointer
XSLT v2
Sturkturmechanismen und
erweiterbares Typsystem
...
Blueburry
release
„XML
v2.0“
2nd edition
t
2001-06-28
11
Research and Technology
XML-Schema ... in zehn Punkten
Erlaubt die Erstellung regulärer kontextfreier Grammatiken für XML-Vokabulare
Part 1 beschreibt Strukturen und Inhaltseinschränkungen
Part 2 definiert Datentypdefinition für Schema Part 1 und weitere XML-Vokabulare
Signifikante Erweiterung der DTD-Mächtigkeit, wird diese langfristig ersetzen
Ist eine XML-Sprache
Integriert die wichtigsten konkurrierenden Vorgängeransätze
Seit 2001-05-02 W3C Recommendation
Basis aller W3C-Standards der zweiten Generation (XPath v2.0, XSLT v2.0, XHTML v2.0, XMLP, ...)
Werkzeugunterstützung verfügbar
Erster Schritt der Schema-Bestrebungen, weitere werden folgen ...
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
12
Research and Technology
XML-Schema ... ein Beispieldokument
<?xml
<?xmlversion="1.0"
version="1.0"encoding="UTF-8"?>
encoding="UTF-8"?>
<Vortrag>
<Vortrag>
<Titel>XML
<Titel>XMLund
undJava
Java––wohin
wohingeht
gehtdie
dieReise?</Titel>
Reise?</Titel>
<Veranstaltung
<Veranstaltungdatum="2001-06-28">
datum="2001-06-28">
<Name>Java
<Name>JavaForum
ForumStuttgart
Stuttgart2001</Name>
2001</Name>
</Veranstaltung>
</Veranstaltung>
<Referent>
<Referent>
<Name>Mario
<Name>MarioJeckle</Name>
Jeckle</Name>
<Firma>DaimlerChrysler
<Firma>DaimlerChryslerResearch
Researchand
andTechnology</Firma>
Technology</Firma>
<URL>http://www.jeckle.de</URL>
<URL>http://www.jeckle.de</URL>
<E-Mail>[email protected]</E-Mail>
<E-Mail>[email protected]</E-Mail>
</Referent>
</Referent>
</Vortrag>
</Vortrag>
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
13
Research and Technology
XML-Schema ... eine beschreibende Grammatik
<?xml
<xsd:element
<?xmlversion="1.0"
version="1.0"encoding="UTF-8"?>
encoding="UTF-8"?>
<xsd:elementname="Name"
name="Name"type="xsd:string"/>
type="xsd:string"/>
<xsd:schema
<xsd:element
name="Referent">
<xsd:schema
<xsd:element name="Referent">
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType>
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType>
<xsd:element
name="Vortrag">
<xsd:sequence>
<xsd:element name="Vortrag">
<xsd:sequence>
<xsd:complexType>
<xsd:element
<xsd:complexType>
<xsd:elementref="Name"/>
ref="Name"/>
<xsd:sequence>
<xsd:element
name="Firma"
<xsd:sequence>
<xsd:element name="Firma"type="xsd:string"
type="xsd:string"
<xsd:element
minOccurs="0"/>
<xsd:elementname="Titel"
name="Titel"type="xsd:string"/>
type="xsd:string"/>
minOccurs="0"/>
<xsd:element
<xsd:element
<xsd:elementref="Veranstaltung"/>
ref="Veranstaltung"/>
<xsd:elementname="URL"
name="URL"type="xsd:anyURI"
type="xsd:anyURI"
<xsd:element
ref="Referent"/>
minOccurs="0"/>
<xsd:element ref="Referent"/>
minOccurs="0"/>
</xsd:sequence>
<xsd:element
</xsd:sequence>
<xsd:elementname="E-Mail"
name="E-Mail"minOccurs="0">
minOccurs="0">
</xsd:complexType>
<xsd:simpleType>
</xsd:complexType>
<xsd:simpleType>
</xsd:element>
<xsd:restriction
</xsd:element>
<xsd:restrictionbase="xsd:string">
base="xsd:string">
<xsd:element
<xsd:pattern
value="\c{1,}@\c{1,}.\c{2,3}"/>
<xsd:elementname="Veranstaltung">
name="Veranstaltung">
<xsd:pattern value="\c{1,}@\c{1,}.\c{2,3}"/>
<xsd:complexType>
</xsd:restriction>
<xsd:complexType>
</xsd:restriction>
<xsd:sequence>
</xsd:simpleType>
<xsd:sequence>
</xsd:simpleType>
<xsd:element
ref="Name"/>
</xsd:element>
<?xmlversion="1.0"
version="1.0"encoding="UTF-8"?>
encoding="UTF-8"?>
<xsd:element ref="Name"/>
</xsd:element> <?xml
<Vortrag>
</xsd:sequence>
<Vortrag>
</xsd:sequence>
</xsd:sequence>
</xsd:sequence>
<Titel>XML
<Titel>XMLund
undJava
Java––wohin
wohingeht
gehtdie
dieReise?</Titel>
Reise?</Titel>
<xsd:attribute
</xsd:complexType>
<Veranstaltung
datum="2001-06-28">
<xsd:attributeref="datum"/>
ref="datum"/>
<Veranstaltung
datum="2001-06-28">
</xsd:complexType>
<Name>Java
</xsd:complexType>
<Name>JavaForum
ForumStuttgart
Stuttgart2001</Name>
2001</Name>
</xsd:element>
</xsd:complexType>
</xsd:element>
</Veranstaltung>
</Veranstaltung>
</xsd:element>
</xsd:schema>
<Referent>
</xsd:element>
<Referent>
</xsd:schema>
<Name>Mario
<xsd:attribute
name="datum"
type="xsd:date"/>
<Name>MarioJeckle</Name>
Jeckle</Name>
<xsd:attribute name="datum" type="xsd:date"/>
M. Jeckle – XML und Java -- wohin geht die Reise?
<Firma>DaimlerChrysler
<Firma>DaimlerChryslerResearch
Researchand
andTechnology</Firma>
Technology</Firma>
<URL>http://www.jeckle.de</URL>
<URL>http://www.jeckle.de</URL>
<E-Mail>[email protected]</E-Mail>
<E-Mail>[email protected]</E-Mail>
</Referent>
</Referent>
2001-06-28 14
</Vortrag>
</Vortrag>
Research and Technology
XML-Schema ... Mächtigkeit
•Strukturell: Attribute und Elemente (wie in DTDs)
•Namespace-Unterstützung
•Atomare Datentypen (int, float, boolean, ...)
•Anwenderdefinierte
•atomare skalare Datentypen (simpleType)
•Einschränkung des Wertebereichs (Domänenrestriktion)
•lexikalische Muster (reguläre Ausdrücke)
•Aufzählungstypen
•Mengentypen
•komplexe Datentypen (complexType)
•Wiederverwendungsunterstützung
•Vererbung: Restriktion und Erweiterung
•Schemafragmente: Typen, Attribut- und Elementgruppen
•Substitution
•Erweiterter Schlüsselmechanismus
•NULL-Werte
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
15
Research and Technology
XML Schema: Datentypen
Ur-typ
Vordefinierter
Primitivtyp
Vordefinierter
abgeleiteter Typ
Typeinschränkung
Aggregierter Typ
Aus: XML-Schema Part 2: Datatypes,
W3C-Recommendation 2001-05-02, chap. 3
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
16
Research and Technology
XML Schema: Datentypen und ihre Abbildung nach Java
string
(length==1)
long
char
IntegralType
long
int
NumericType
FloatingPointType
boolean
M. Jeckle – XML und Java -- wohin geht die Reise?
...
int
short
PrimitiveType
...
short
byte
byte
float
float
double
double
boolean
2001-06-28
17
Research and Technology
XML-basierte RPC-Mechanismen: SOAP, ...
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
18
Research and Technology
XML-basierte RPC-Mechanismen: SOAP, ...
POST /soap/servlet/rpcrouter HTTP/1.0
POST /soap/servlet/rpcrouter HTTP/1.0
Host: localhost:8081
Host: localhost:8081
Content-Type: text/xml; charset=utf-8
Content-Type: text/xml; charset=utf-8
Content-Length: 474
Content-Length: 474
SOAPAction: ""
SOAPAction: ""
<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Body>
<ns1:add xmlns:ns1="urn:NumberAdder"
<ns1:add xmlns:ns1="urn:NumberAdder"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<number1 xsi:type="xsd:int">1</number1>
<number1 xsi:type="xsd:int">1</number1>
<number2 xsi:type="xsd:int">2</number2>
<number2 xsi:type="xsd:int">2</number2>
</ns1:add>
</ns1:add>
</SOAP-ENV:Body>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</SOAP-ENV:Envelope>
HTTP-Port
Web-Server
Web-Server
HTTP-Port
Request
Firewall
M. Jeckle – XML und Java -- wohin geht die Reise?
Firewall
2001-06-28
19
Research and Technology
XML-basierte RPC-Mechanismen: SOAP, ...
HTTP/1.0 200 OK
HTTP/1.0 200text/xml;
OK
Content-Type:
charset=utf-8
Content-Type: 529
text/xml; charset=utf-8
Content-Length:
Content-Length:
529
Set-Cookie2:
JSESSIONID=tibpjehn11;Version=1;Discard;Path="/soap"
Set-Cookie2:
JSESSIONID=tibpjehn11;Version=1;Discard;Path="/soap"
Set-Cookie:
JSESSIONID=tibpjehn11;Path=/soap
Set-Cookie: JSESSIONID=tibpjehn11;Path=/soap
Servlet-Engine:
Tomcat Web Server/3.2.1
Servlet-Engine:
Tomcat
Web Server/3.2.1
(JSP
1.1; Servlet 2.2;
Java 1.3.0;
Windows 2000 5.0 x86; java.vendor=Sun Microsystems Inc.)
(JSP 1.1; Servlet 2.2; Java 1.3.0; Windows 2000 5.0 x86; java.vendor=Sun Microsystems Inc.)
<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Body>
<ns1:addResponse
<ns1:addResponse
xmlns:ns1="urn:NumberAdder"
xmlns:ns1="urn:NumberAdder"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return
xmlns:ns2="http://xml.apache.org/xml-soap"
<return
xmlns:ns2="http://xml.apache.org/xml-soap"
xsi:type="ns2:Vector">
xsi:type="ns2:Vector">
<item xsi:type="xsd:int">3</item>
<item xsi:type="xsd:int">3</item>
</return>
</return>
</ns1:addResponse>
</ns1:addResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</SOAP-ENV:Envelope>
HTTP-Port
Web-Server
Web-Server
HTTP-Port
Response
Firewall
M. Jeckle – XML und Java -- wohin geht die Reise?
Firewall
2001-06-28
20
Research and Technology
XML-basierte RPC-Mechanismen: SOAP/XMLP vs. RMI
Programmiermodellneutral
Sprachunabhängig
LS
XM
Lesbarer Text
(human readable)
Firewallüberwindung
Hauptnutzung:
B2B
asynchron
Zentrale
Registrierungsinstanz
synchron
ch
em
a
Plattformunabhängigkeit
Typsystem
Hauptnutzung:
A2A
SOAP/
XMLP
Objektorientiert
Transportprotokoll
Verbosität unabhängigkeit
M. Jeckle – XML und Java -- wohin geht die Reise?
Effiziente
Binärrepräsentation
Verteilungsunterstützung
2001-06-28
21
Das XML-Universum
Research and Technology
Sprachentwurf
Programmierung/
Schnittstellen
XML-Schema (XSD)
DDML
Schematron
RELAX NG
<?XML!>
DCD
DOM
SAX
Editoren
Anwendungen
XML-RPC
SOAP/XMLP
Protokolle
M. Jeckle – XML und Java -- wohin geht die Reise?
Werkzeugunterstützung
2001-06-28 22
Stylesheet-, Linkingprozessoren,
...
Research and Technology
XML und Java ... Simple API for XML (SAX)
Entwickelt durch Mitglieder der Mailingliste xml-dev
auf Initiative von David Megginson
Zusammenstellung sprachunabhängiger Schnittstellen
Light-weight:
•einfach (in eigenen Programmen) einzusetzen
•einfach (in beliebige Programmiersprachen) umzusetzen
Serieller linearer ereignisbasierter Parsingvorgang
Definiert und erfordert keine Speicherstrukturen
SAX ist eine Schnittstelle für Parser, kein Parser!
Laufzeitverhalten skaliert linear mit Dokumentgröße
JAXP und J2SE v1.4 enthält (vermutlich) eine Implementierung des aktuellen Standes SAX2
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
23
Research and Technology
XML und Java ... Simple API for XML (SAX)
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
Implementierung der Standardschnittstelle
public class SAXExample extends DefaultHandler
{
public void startDocument()
{
//...
} //startDocument()
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
{
// ...
} //startElement()
public static void main (String args[]) throws Exception
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse( args[0], new SAXExample() );
} //main()
}//class SAXExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
24
Research and Technology
XML und Java ... Simple API for XML (SAX)
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
SAX-Parserimplementierung der JAXP
public class SAXExample extends DefaultHandler
{
public void startDocument()
{
//...
} //startDocument()
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
{
// ...
} //startElement()
public static void main (String args[]) throws Exception
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse( args[0], new SAXExample() );
} //main()
}//class SAXExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
25
Research and Technology
XML und Java ... Simple API for XML (SAX)
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class SAXExample extends DefaultHandler
{
public void startDocument()
{
//...
} //startDocument()
public void startElement(String namespaceURI,
String localName, String qName, Attributes atts)
{
// ...
} //startElement()
public static void main (String args[]) throws Exception
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse( args[0], new SAXExample() );
} //main()
}//class
SAXExample
M. Jeckle
– XML und Java -- wohin geht die Reise?
Durch SAX in ihrer Signatur
vorgegebene
Callback-Methoden
2001-06-28
26
Research and Technology
XML und Java ... Simple API for XML (SAX)
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class SAXExample extends DefaultHandler
{
public void startDocument()
{
//...
} //startDocument()
public void startElement(String namespaceURI,
String localName, String qName, Attributes atts)
{
// ...
} //startElement()
public static void main (String args[]) throws Exception
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse( args[0], new SAXExample() );
} //main()
}//class
SAXExample
M. Jeckle
– XML und Java -- wohin geht die Reise?
Erzeugung eines SAX-basierten
Parsers und
prüfen eines XML-Dokuments
2001-06-28
27
Research and Technology
XML und Java ... Document Object Model (DOM)
W3C standardisierte API für HTML, XML, CSS, etc.
Stand: Recommendation: DOM Level 1, Level 2; Working Draft: Level 3
Definiert programmiersprachenunabhängige (beschrieben durch CORBA IDL)
baumartige objektorientierte Speicherstruktur für XML mit Operationen
zur Navigation und Manipulation
(z.B. Elemente ändern, löschen, hinzufügen)
Zumeist auf Basis eines SAX-basierten Parsingvorganges erzeugt
Speicheraufwand zur Verwaltung des gesamten XML-Dokuments im Hauptspeicher teilweise sehr hoch
Mit JDOM existiert eine für Java optimierte moderne Implementierung
(d.h. Berücksichtigung von XML-Schema, Nutzung der Collection- und Reflection API, etc.)
Verfügbar: Diverse Implementierungen; JDOM, DOM4J
JDOM: JSR
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
28
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Implementierung der Standardschnittstellen
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
29
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Erzeugung des
Parsers und Einlesevorgang
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
30
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
Extraktion eines
Elements
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
31
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Hinzufügen eines
(neuen) Attributs
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
32
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
Erzeugung eines
neuen Elements
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
33
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
Anhängen des erzeugten
Elements als zusätzliches Kindelement
2001-06-28
34
Research and Technology
XML und Java ... Document Object Model (DOM)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMExample
{
public static void main(String[] args) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( args[0] );
Element theRootElement = document.getDocumentElement();
theRootElement.setAttribute("myFirstNewAttribute","01");
Element aNewElement = document.createElement("myNewElement");
theRootElement.appendChild( aNewElement );
System.out.print( theRootElement );
} //main()
} //class DOMExample
M. Jeckle – XML und Java -- wohin geht die Reise?
Ausgabe des gesamten Dokuments
auf Standard-out
2001-06-28
35
Research and Technology
Java und XML … Java XML API for XML Processing (JAXP)
Berücksichtigt:
•XML v1.0 2nd editon ;)
•Namespaces
•SAX v2.0
•DOM Level 2
•XSLT v1.0
Plugability layer realisiert Informationsmöglichkeit hinsichtlich
Implementierung der Parser
JAXP v1.0 ist (vermutlich) Bestandteil von J2SE v1.4
Verfügbar: JAXP v1.1: JSR, Spezifikation, Implementierung
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
36
Research and Technology
Java und XML ... Java APIs for XML Messaging (JAXM)
Grundidee: Austausch von XML-codierten Business Dokumenten
(z.B. Bestellungen, Rechnungen oder Auftragsbestätigungen)
Definiert keine neuen XML-Vokabulare für den Anwendungsbereich
Entwickelt in Abstimmung mit ähnlichen Aktivitäten des W3C,
ebXML (Transport/Packaging & Routing)
Transport über (Internet-)Standardprotokolle wie HTTP(S) oder SMTP
Explizite Berücksichtung der SOAP v1.1-Spezifikation
Applikation1
JAXM-Service
SOAP
JAXM
JAXM-API
Verfügbar: JSR, Spezifikation v0.92 (Juni 2001)
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
37
Research and Technology
Java und XML ... Java APIs for XML RPC (JAXRPC)
Grundidee: Übertragung von entfernten Methodenaufrufen mittels XML
Überlappung mit SOAP/XMLP; jedoch koordiniert mit W3C-Aktivitäten hierzu
APIs definieren stubs und skelettons zur Erzeugung der notwendigen
XML-Dokumente auf Seiten des Aufrufers bzw. Aufgerufenen
API zur Vermittlung der XML-RPCs an Java-Objekte
Verbindung zu JAXB (XML Serialisierung von Java-Objekten)
Verfügbar: JSR
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
38
Research and Technology
Java und XML ... Java API for XML Registries (JAXR)
Grundidee: API zum Zugriff auf Dienstverzeichnisse
Analog zu Java Naming and Directory Interface (JDNI),
jedoch speziell für Bedürfnisse von Web-Services zugeschnitten
Service Discovery
Service Descriptions
Standard-API zum Zugriff auf:
eCo Framework, ebXML, UDDI
Definiert keinen neuen
eigenen Verzeichnisdienst
Bestandteil von J2EE
Inter-Application Transport
ADS, DISCO, UDDI,
UDDI, WSDL
SOAP / W3C’s XML Protocols
Application Layer
...
Presentation Layer
XML-Languages
Session Layer
CORBA, HTTP,RMI, SMTP, WSP
Transport Layer
TCP, WTP, UDP
Network Layer
IP, X.25, IPX
Data Link Layer
HDLC, SLIP, PPP, Ethernet, IEEE 802.x
Physical Layer
analogous Modem, V. 90, ISDN, ADSL
Verfügbar: JSR; (public draft für Q2 2001 zu erwarten)
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
39
Research and Technology
Java und XML ... Java Architecture for XML Binding (JAXB)
Grundidee: Verringerung des Impedance Mismatch zwischen Java und XML
Technisch: Generierung von Java-Klassendefinitionen aus
Grammatik (Document Type Definitions oder XML Schema) und einer
Abbildungsdefinition
DTD/
XSD
Schema
Compiler
binding
schema
Java
Compiler
Java-Quellcode
Java-Bytecode
JAXB v1.0 ist (vermutlich) Bestandteil von J2SE v1.4
Verfügbar: JSR, early acces v1.0 Implementierung (Mai 2001)
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
40
Research and Technology
Ressourcen
XML @ W3C:
•http://www.w3.org/xml
XML @ SUN:
•http://java.sun.com/xml
•http://www.javasoft.com/xml
Java XML Projekte @ Apache:
•http://xml.apache.org
Diese Vortrag und weiterführende Informationen zum Thema:
•http://www.jeckle.de
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
41
Research and Technology
Ressourcen
Java Community Process (JCP):
•http://java.sun.com/aboutJava/communityprocess/index.html
•(Merlin JSR) http://jcp.org/jsr/detail/59.jsp
•Java Architecture for XML Binding (ehemals Projekt Adelard) (JAXB)
•http://jcp.org/jsr/detail/31.jsp
•http://www.javaworld.com/javaworld/javaone00/j1-00-adelard.html
•Java API for XML Processing v1.1 (JAXP)
•Version 1.0: http://jcp.org/jsr/detail/5.jsp
•Version 1.1: http://jcp.org/jsr/detail/63.jsp
•Java API for XML Messaging v1.0 (JAXM)
•http://jcp.org/jsr/detail/67.jsp
•Java API for XML Registries v1.0 (JAXR)
•http://jcp.org/jsr/detail/93.jsp
•Java APIs for XML RPC(JAXRPC)
•http://jcp.org/jsr/detail/101.jsp
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
42
Research and Technology
Ressourcen
SAX-Parser für Java:
•http://home.pacbell.net/david-b/xml (Ælfred)
•http://java.sun.com/products/xml (JAXP)
•http://technet.oracle.com
•http://www.alphaworks.ibm.com/formula/xml (XML4J)
•http://www.jclark.com/xml/xp/index.html (XP)
•http://xml.apache.org/xerces-j/index.html (Xerces)
DOM-Parser für Java:
•http://java.sun.com/products/xml (JAXP)
•http://www.alphaworks.ibm.com/formula/xml (XML4J)
•http://xml.apache.org/xerces-j/index.html (Xerces)
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
43
Research and Technology
Ressourcen
Java Serialization to XML (JSX):
•http://www.csse.monash.edu.au/~bren/JSX/
JDOM v1.0:
•http://jcp.org/jsr/detail/102.jsp
DOM4J:
•http://dom4j.org/
Electric XML:
•http://www.themindelectric.com/products/xml/xml.html
Java XML Tutorial @ SUN:
•http://java.sun.com/xml/tutorial_intro.html
JavaML:
•http://www.cs.washington.edu/homes/gjb/JavaML/
M. Jeckle – XML und Java -- wohin geht die Reise?
2001-06-28
44
Herunterladen