! " #$%&
0 ) ( )" %+ %*,( )" -" ".. /+% ()( )" ' &2 34%* 5 &2 ( )" " & 6 7 83-4 6& )9 2) " * 1
6 5 75 6 5 75 %* %* 32 %,6,) 5 " )& 8 * 2-4;< 7)&%*2 : = 75 75 75 %* 32,) 5, 37 %,2-4;< 7)&%*2
?7 7 (? A% % A%4A&%+8 A%A5 (?4( "?@ %4" 7%+8 > B
! 83 %+ 73 A&%+ $* * &7 3$4D D EE- ) 'D 8 74FF***2/7 @ 2 F C " # % " % H 5 4,) 5 7 5&G %*
$ <pricelist> <coffee> <name> Mocha Java </name> <price> 11.95 </price> </coffee> </pricelist> 8startElement(,priceList, ) 82 8startElement(,coffee, ) 82 8startElement(,name, ) 82 8characters("Mocha Java", ) 82 8endElement(,name,..) 82 8startElement(,price, ) 82 8characters("11.95", ) 82 8endElement(,price, ) 82 8endElement(,coffee, ) 82 8endElement(,priceList, ) 82 58 84 5 7* * %* 2-45 * )-" 8= %# 5&G I %* J & " 88* 83@,) 5 D ) 224 - startdocument enddocument - startelementendelement - characters - processinginstruction DefaultHandler +" 7" D ) 4 @* = )93 *
startelement public void startelement(java.lang.string uri, java.lang.string localname, java.lang.string qname, Attributes attributes) throws SAXException uri4! " " -$ localname4 )! " 68/ qname4! " " 68/ attributes4$" 5 " 9% %)93 I+/J! " $88* endelement 6 @ attributes ' characters public void characters(char[] buffer, int offset, int length) throws SAXException buffer: & 0 offset4%8/ offset+length String s = new String(buffer, offset, length); 1
$ <pricelist> <coffee> <name> Mocha Java </name name> <price> 11.95 </price price> </coffee> </pricelist> %84K & A&= G 839* $* (4 2 % 2 7D ) : & # ' SAXParserFactory factory = SAXParserFactory.newInstance(); 8SAXParserFactory SAXParser saxparser = factory.newsaxparser(); 8SAXParser saxparser.parse("pricelist.xml", handler); 9H% pricelist.xml: $7() L M " handler: +$& DefaultHandler" 7" D )N )
"() )* 5 * 8" ;(O& K " " G " A ICC:J 8?@)?@)+$) " +8 2 ) F+8 & " " 7" -74Iterator i = list.iterator(); -74SAXParser saxparser = factory.newsaxparser(); > % %# <pricelist> <coffee> <name> Mocha Java </name> <price> 11.95 </price> </coffee> </pricelist> 06 5" P" inname P A& inmochajava 5" P7 inmjprice P print(s) B
%# + public void startelement(..., String elementname,,...) { if (elementname.equals("name")){ inname = true; } else if (elementname.equals("price") && inmochajava ){ inmjprice = true; inmochajava = false; } } public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname && s.equals("mocha Java")) { inmochajava = true; inname = false; } else if (inmjprice) { System.out.println("The price of Mocha Java is: " + s); inmjprice = false; } } C!<name name>, public void startelement(..., String elementname,...){ if (elementname.equals("name")){")){ inname = true; } else if (elementname.equals("price") && inmochajava ){ inmjprice = true; <name>mocha Java</name> inmochajava = false; } } <price>11.95</price> public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname && s.equals("mocha Java")) { inmochajava = true; inname = false; } else if (inmjprice) { System.out.println("The %8$ price of Mocha Java is: " + s); inmjprice = false; } } )0 & 0 &P8 inname
inname:!"mocha Java", public void startelement(..., String elementname,...){ if (elementname.equals("name")){ inname = true; } else if (elementname.equals("price") && inmochajava ){ inmjprice = true; inmochajava = false; } } <name>mocha Java</name> <price>11.95</price> public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname && s.equals("mocha Java")) { inmochajava = true; inname = false; } else if (inmjprice) { System.out.println("The price of Mocha Java is: " + s); inmjprice = false; } } inname inmochajava " # public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname)) { if (s.equals("mocha Java")) { inmochajava = true; inname = false; } else inname = false; ; } else if (inmjprice) { System.out.println("The price of Mocha Java is: " + s); inmjprice = false; } } <name>mocha Java</name> <price>11.95</price> inname inmochajava
inmochajava!<price price>, public void startelement(..., String elementname,...){ if (elementname.equals("name")){ inname = true; } else if (elementname.equals("price")") && inmochajava ){ inmjprice = true; <name>mocha Java</name> inmochajava = false; } } <price>11.95</price> public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname && s.equals("mocha Java")) { inmochajava = true; inname = false; } else if (inmjprice) { System.out.println("The price of Mocha Java is: " + s); inmjprice = false; } } inname inmochajava inmjprice ' inmjprice # public void startelement(..., String elementname,...){ if (elementname.equals("name")){ inname = true; } else if (elementname.equals("price") && inmochajava ){ inmjprice = true; inmochajava = false; } } <name>mocha Java</name> <price>11.95</price> public void characters(char [] buf, int offset, int len) { String s = new String(buf, offset, len); if (inname && s.equals("mocha Java")) { inmochajava = true; inname = false; } else if (inmjprice)) { System.out.println("The price of Mocha Java is: : " + s); inmjprice = false; } } inmjprice print(s) 1
) # <pricelist> <coffee> <name> Mocha Java </name> <name> MS Java </name> <price> 11.95 </price> </coffee> </pricelist> 5" P" inname P A& inmochajava 5" P7 inmjprice P print(s) : ) # public void startelement(..., String elementname,...){ if (elementname.equals("name")){ inname = true; } else if (elementname.equals("price")") && inmochajava ){ inmjprice = true; <name>mocha Java</name> inmochajava = false; } } <name>ms Java</name> inmochajava * <price> ) " " <name>* )0 inmochajava &6 ) " " <price>* ) 0 inmjprice & A&* = <price>11.95</price> inname inmochajava inmjprice
) # % 3738" " 8 " ( )" 2 ) 0 6)$2(.( " 3738 " )$2-2(name price) + &,/ )8)% 8 D ) )9& * 8 " $6( )" 2 > - E 88$ H( )" Q /I-" J" & %* &* * 2 Q &,/ Q " 9 ) 8) 5 & ( )" B
. /0 0 1 0!! %* % % startelement characters ($8 ($8 8 8 getpricelist() %* ) +" " %* ) $6 & " ($88I %J2 0 2-2)9 getpricelist() & 82 & %%+ &,/ C 12 '
1 2 #3 412 5 (? %* " " ) ) $" 0 8 8$ 5 & -6" 'D 6& " " 7 83 83G. ( )" " 5 5 ' 12 $/ <?xml version="1.0"?> <pricelist> <coffee> <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> ( "!! 5 "! 4PriceList! 5 "! 4coffee - 4( )" $I( "! J pricelist ( "! 4&( )" $" $2-2 version="1.0" $76 Document Node Element Node " " NodeList '
6 $ <?xml version="1.0"?> <pricelist> <coffee> <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> - 4D(%.%* 2 5 "! 4coffee! 5 "! 4name!. /! 4Mocha Java 5 "! 4price!. /! 411.95 '' - 7! 7& - /! 8D D ()0 883! " " 9 4 getelementsbytagname '1
$ <pricelist> <coffee> <name> Mocha Java </name name> <price> 11.95 </price price> </coffee> </pricelist> %84K & A&= G 839* $* (4 2 (? 2 7 088" ': & # 12 ' DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 8DocumentBuilderFactory DocumentBuilder builder = factory.newdocumentbuilder(); 8(? Document document = builder.parse("pricelist.xml"); (? parse(). 8" ) " 7(?-" '
&.!! ' NodeList coffeenodes = document.getelementsbytagname("coffee"); "); for (int i=0; i < coffeenodes.getlength(); i++) { thiscoffeenode = coffeenodes.item(i); Node thisnamenode = thiscoffeenode.getfirstchild(); String data = thisnamenode.getfirstchild().getnodevalue(); (); if (data.equals("mocha Java")) { Node thispricenode = thisnamenode.getnextsibling(); String price = thispricenode.getfirstchild().getnodevalue(); (); break; } } PA& " " (? $ '> # coffee coffee" 7 NodeList coffeenodes = document.getelementsbytagname("coffee"); "); getelementsbytagname4 )0 888 5 " 3! " * 5 " M" " NodeList <?xml version="1.0"?> <pricelist> <coffee> <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> 'B
$ " coffee coffee 7 NodeList coffeenodes = document.getelementsbytagname("coffee"); for (int i=0; i < coffeenodes.getlength(); i++) { thiscoffeenode = coffeenodes.item(i); } coffeenodes.item(0) <?xml version="1.0"?> <pricelist> <coffee> <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> 'C # coffee coffee7 NodeList coffeenodes = document.getelementsbytagname("coffee"); for (int i=0; i < coffeenodes.getlength(); i++) { thiscoffeenode = coffeenodes.item(i); Node thisnamenode = thiscoffeenode.getfirstchild(); String data = thisnamenode.getfirstchild().getnodevalue(); if (data.equals("mocha Java")) { Node thispricenode = thiscoffeenode.getnextsibling(); String price = thispricenode.getfirstchild().getnodevalue(); <?xml version="1.0"?> <pricelist> break; } } <coffee> 8D <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> 1
# name name7 NodeList coffeenodes = document.getelementsbytagname("coffee"); for (int i=0; i < coffeenodes.getlength(); i++) { thiscoffeenode = coffeenodes.item(i); Node thisnamenode = thiscoffeenode.getfirstchild(); String data = thisnamenode.getfirstchild().getnodevalue(); (); if (data.equals("mocha Java")) { Node thispricenode = thiscoffeenode.getnextsibling(); <?xml version="1.0"?> String price = thispricenode.getfirstchild().getnodevalue(); <pricelist> break; } } 8D <coffee> Element Node: coffee <name>mocha Java</name> NodeList <price>11.95</price> Element Node: name Element Node: price </coffee> NodeList NodeList </pricelist> Text Node: Mocha Java Text Node: 11.95 1 #, " 7 NodeList coffeenodes = document.getelementsbytagname("coffee"); for (int i=0; i < coffeenodes.getlength(); i++) { thiscoffeenode = coffeenodes.item(i); Node thisnamenode = thiscoffeenode.getfirstchild(); String data = thisnamenode.getfirstchild().getnodevalue(); if (data.equals("mocha Java")) { Node thispricenode = thisnamenode.getnextsibling(); String price = thispricenode.getfirstchild().getnodevalue(); <?xml version="1.0"?> break; } } <pricelist> <coffee> <name>mocha Java</name> / <price>11.95</price> </coffee> </pricelist> 1
# price price7 NodeList coffeenodes = document.getelementsbytagname("coffee"); <?xml version="1.0"?> <pricelist> for (int i=0; i < coffeenodes.getlength(); i++) { <coffee> thiscoffeenode = coffeenodes.item(i); <name>mocha Java</name> Node thisnamenode = thiscoffeenode.getfirstchild(); <price>11.95</price> String data = thisnamenode.getfirstchild().getnodevalue(); </coffee> 8D if (data.equals("mocha Java")) { </pricelist> Node thispricenode = thisnamenode.getnextsibling(); String price = thispricenode.getfirstchild().getnodevalue(); (); break; } } 1' - 12 E /I-" J" & %* &* * 2 E )0 8885 " 3! " E 8) 5 & ( )" Q 7 & Q &,/ 11
12 ' % " $" ". & ( )" $8 $" 76 0 7). ( )" $9 )5 8$& ( )" (? " 8. ( )" $& 0 7) $$8 5 8$& ( )" 1: 8# 0 1
8# 0 Datenabstraktion Java- Klassen Instanzen Java- Objekte XML- Schema Instanz XML- Dokument Übersetzen Validieren Deserialisieren Serialisieren F * 2 0* )4 & 8$ 5& ( )" A%-4A&% 8 -. & A& & (& 7 ) 1> $ <pricelist> <coffee> <name>mocha Java</name> <price>11.95</price> </coffee> </pricelist> " A%- public interface PriceList { java.util.list getcoffee(); public interface CoffeeType { String getname(); void setname(string value) java.math.bigdecimal getprice(); void setprice(java.math.bigdecimal value) } } 1B
8# 0xsd:choice <xs:element name="boolcommentorvalue"> <xs:complextype> <xs:choice> <xs:element name="bool" type="xs:boolean"/> <xs:element name="comment" type="xs:string"/> <xs:element name="value" type="xs:int"/> </xs:choice> </xs:complextype> </xs:element> )(,7 A&3$ * 1C 8# 0xsd:choice <xs:element name="boolcommentorvalue"> <xs:complextype> public interface BoolCommentOrValue { <xs:choice> int getvalue(); <xs:element name="bool" type="xs:boolean"/> void setvalue(int value); <xs:element name="comment" boolean type="xs:string"/> issetvalue(); <xs:element name="value" type="xs:int"/> java.lang.string getcomment(); </xs:choice> void setcomment(java.lang.string value); </xs:complextype> boolean issetcomment(); </xs:element> boolean getbool(); void setbool(boolean value); boolean issetbool(); Object getcontent(); boolean issetcontent(); void unsetcontent(); } :
& ' " # $4 " )A& D R 3$* 2 G " )9( )" " 8$ * 2 " " " 68 : 9* "$ 3 08 - &* 3+ " K 68* )2 " 3 8% 8 " 2 :
"$ 3 K 68 * K 7- K 6876 * K 0 4- N " " 8* % )* )" " - 2 :' "$ 3 XML - N " " " " 6,/ %8 M $* 8*2 " " )9 " # $ $& 2 :1
& # /! ' +4 8* % ) 68 &" 7 - " 2 ++4 " " )9 " # $ $& 2 @)8* + ++ SBT :: &, ' / (?! & %(? " # $ # '2# 422K 77 6. 8 " & ( )" ". :