1 / 20

IA307 - Data Exchange with XML

IA307 - Data Exchange with XML. Christophe Coenraets Manager, Technical Evangelists Internet Applications Division ccoenrae@sybase.com. Topics. Drawbacks of HTML What is XML? Document Type Declaration (DTD) Extensible Style Language (XSL) XML and Java Simple API for XML (SAX)

brita
Download Presentation

IA307 - Data Exchange with XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IA307 - Data Exchange with XML Christophe Coenraets Manager, Technical Evangelists Internet Applications Division ccoenrae@sybase.com

  2. Topics • Drawbacks of HTML • What is XML? • Document Type Declaration (DTD) • Extensible Style Language (XSL) • XML and Java • Simple API for XML (SAX) • Document Object Model (DOM)

  3. TripFinder.htm Page <center><h1>Trip Finder</h1> <form action="TripFinder.jsp"> <table border=0> <tr><td>Origin:</td><td><input name="origin" value="bos"></td></tr> <tr><td>Destination:</td><td><input name="destination" value="ARU"></td></tr> <tr><td>Date:</td><td><input name="date" value="01/01/1900"></td></tr> </table><br><input type="submit" value="Search"></form> <p><table border=1 cellpadding=4> <tr><td><a href=Payment.jsp?trip=2&amount=2200>Book it</a></td> <td>TNT</td><td>Grand Hyatt Aruba</td><td>2000-05-01</td><td>7</td><td>2200</td></tr> <tr><td><a href=Payment.jsp?trip=8&amount=1900>Book it</a></td> <td>TNT</td><td>Plaza Hotel</td><td>2000-06-01</td><td>7</td><td>1900</td></tr> <tr><td><a href=Payment.jsp?trip=9&amount=2100>Book it</a></td> <td>GWV</td><td>Marriott Aruba</td><td>2000-06-01</td><td>7</td><td>2100</td></tr> </table></center>

  4. Drawbacks of HTML • HTML document contains both data and formatting • HTML tags • Describe how page elements should look • Don't contain any information about what the data is • Issues • Difficult to identify and extract data from the document • Difficult to change the presentation style

  5. What is XML? • Extensible Markup Language • World Wide Web Consortium standard that lets you create your own tags • Universal data description mechanism • XML separates the data and presentation • Makes documents suitable for data interchange • Allows alternative presentation styles • Simplifies business-to-business transactions on the web

  6. XML DocumentTrip.xml <?xml version="1.0" ?> <trip> <trip_id>2</trip_id> <origin>BOS</origin> <destination>ARU</destination> <hotel>Grand Hyatt Aruba</hotel> <arrival_date>2000-05-01</arrival_date> <days>7</days> <price>2200</price> </trip>

  7. XML Document Characteristics • No presentation information • No specification of type style or color • No specification of format: table, list, bold, etc • Tags are application-oriented • <destination>, <hotel>, etc, instead of just <p> • Easy to distinguish “123” as TripId vs Price

  8. Enabling Business-to-Business (B2B) <TripRequest> </TripRequest> Tour Operator <TripList></TripList> Travel Agent TripList.xmlTripList.xsl <TripList></TripList> Tour Operator <TripRequest> </TripRequest>

  9. Well Formed XML documents • An XML document is well-formed if it is syntactically correct • Document starts with <?xml…> • Tags are strictly nested • Each open <tag> has a corresponding close </tag>

  10. Valid XML documents • An XML document is valid if it specifies and conforms to the document rules defined in a DTD • Valid XML documents are well-formed • Well-formed XML documents may be valid

  11. Document Type Declaration (DTD) • Specifies a Document Type • Defines set of rules, grammar document must comply to • Allows for predictable data

  12. Vacation DTDExample <!ELEMENT trip (origin, destination, hotel, arrival, nights, price)> <!ELEMENT origin (#PCDATA)> <!ELEMENT destination (#PCDATA)> <!ELEMENT hotel (#PCDATA)> <!ELEMENT arrival (#PCDATA)> <!ELEMENT nights (#PCDATA)> <!ELEMENT price (single, double)> <!ELEMENT single (#PCDATA)> <!ELEMENT double (#PCDATA)> <!ATTLIST hotel rating (na|1|2|3|4) "na">

  13. XML DocumentTrips.xml <?xml version="1.0" ?> <!DOCTYPE vacation SYSTEM "vacation.dtd"> <trips> <trip> <trip_id>2</trip_id> <origin>BOS</origin> <destination>ARU</destination> <hotel>Grand Hyatt Aruba</hotel> <arrival_date>2000-05-01</arrival_date> <days>7</days> <price>2200</price> </trip> </trips>

  14. Presentation Using XSL • XML documents omit all formatting • Formatting is supplied by XSL • XSL: “Extensible Style Language” • Specified separate from the XML document • Allows multiple XSL specs for one XML document • An XSL spec maps • An XML document type to HTML, or • One XML document type to another

  15. XML and Java • Java and XML are complementary Technologies • Java = Code Portability • XML = Data Portability • Java Parsers facilitate XML document manipulation • Validate an XML document • Handle character set issues, etc • Return a Java object (a tree) for the document • Also used to build such a tree and generate a document

  16. XML Parsers • Many XML parsers are available • Often with free license or public domain • XML parsers use two standard interfaces • SAX and DOM • Applications using SAX & DOM • Can be portable across XML parsers

  17. Simple API for XML (SAX) • Event-driven interface to XML parsers • org. xml. sax.* package Event <?xml version="1.0" ?> <trip> … </trip> Event SAX Event

  18. Document Object Model (DOM) • Tree data structure interface to XML parser • Models document structure as objects • Defines a Java programming language binding: • org. w3c. dom.* package • DOM is also used to build XML documents <?xml version="1.0" ?> <trip> … </trip> DOM

  19. Creating TripListXML.jspDemo Tour Operator <TripList></TripList> Travel Agent TripList.xmlTripList.xsl <TripList></TripList> Tour Operator

  20. Summary

More Related