Title: Enabling Data Exchange with XML
1IA307 - Data Exchange with XML
Christophe Coenraets Manager, Technical
Evangelists Internet Applications
Division ccoenrae_at_sybase.com
2Topics
- 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)
3TripFinder.htm Page
- ltcentergtlth1gtTrip Finderlt/h1gt
- ltform action"TripFinder.jsp"gt
- lttable border0gt
- lttrgtlttdgtOriginlt/tdgtlttdgtltinput name"origin"
value"bos"gtlt/tdgtlt/trgt - lttrgtlttdgtDestinationlt/tdgtlttdgtltinput
name"destination" value"ARU"gtlt/tdgtlt/trgt - lttrgtlttdgtDatelt/tdgtlttdgtltinput name"date"
value"01/01/1900"gtlt/tdgtlt/trgt - lt/tablegtltbrgtltinput type"submit"
value"Search"gtlt/formgt - ltpgtlttable border1 cellpadding4gt
- lttrgtlttdgtlta hrefPayment.jsp?trip2amount2200gtBoo
k itlt/agtlt/tdgt - lttdgtTNTlt/tdgtlttdgtGrand Hyatt Arubalt/tdgtlttdgt2000-05-
01lt/tdgtlttdgt7lt/tdgtlttdgt2200lt/tdgtlt/trgt - lttrgtlttdgtlta hrefPayment.jsp?trip8amount1900gtBoo
k itlt/agtlt/tdgt - lttdgtTNT lt/tdgtlttdgtPlaza Hotellt/tdgtlttdgt2000-06-01lt/t
dgtlttdgt7lt/tdgtlttdgt1900lt/tdgtlt/trgt - lttrgtlttdgtlta hrefPayment.jsp?trip9amount2100gtBoo
k itlt/agtlt/tdgt - lttdgtGWVlt/tdgtlttdgtMarriott Arubalt/tdgtlttdgt2000-06-01lt
/tdgtlttdgt7lt/tdgtlttdgt2100lt/tdgtlt/trgt - lt/tablegtlt/centergt
4Drawbacks 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
5What 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
6XML DocumentTrip.xml
- lt?xml version"1.0" ?gt
- lttripgt
- lttrip_idgt2lt/trip_idgt
- ltorigingtBOSlt/origingt
- ltdestinationgtARUlt/destinationgt
- lthotelgtGrand Hyatt Arubalt/hotelgt
- ltarrival_dategt2000-05-01lt/arrival_dategt
- ltdaysgt7lt/daysgt
- ltpricegt2200lt/pricegt
- lt/tripgt
7XML Document Characteristics
- No presentation information
- No specification of type style or color
- No specification of format table, list, bold,
etc - Tags are application-oriented
- ltdestinationgt, lthotelgt, etc, instead of just ltpgt
- Easy to distinguish 123 as TripId vs Price
8Enabling Business-to-Business (B2B)
ltTripRequestgt lt/TripRequestgt
Tour Operator
ltTripListgtlt/TripListgt
Travel Agent
TripList.xmlTripList.xsl
ltTripListgtlt/TripListgt
Tour Operator
ltTripRequestgt lt/TripRequestgt
9Well Formed XML documents
- An XML document is well-formed if it is
syntactically correct - Document starts with lt?xmlgt
- Tags are strictly nested
- Each open lttaggt has a corresponding close lt/taggt
10Valid 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
11Document Type Declaration (DTD)
- Specifies a Document Type
- Defines set of rules, grammar document must
comply to - Allows for predictable data
12Vacation DTDExample
- lt!ELEMENT trip (origin, destination, hotel,
arrival, nights, price)gt - lt!ELEMENT origin (PCDATA)gt
- lt!ELEMENT destination (PCDATA)gt
- lt!ELEMENT hotel (PCDATA)gt
- lt!ELEMENT arrival (PCDATA)gt
- lt!ELEMENT nights (PCDATA)gt
- lt!ELEMENT price (single, double)gt
- lt!ELEMENT single (PCDATA)gt
- lt!ELEMENT double (PCDATA)gt
- lt!ATTLIST hotel rating (na1234) "na"gt
13XML DocumentTrips.xml
- lt?xml version"1.0" ?gt
- lt!DOCTYPE vacation SYSTEM "vacation.dtd"gt
- lttripsgt
- lttripgt
- lttrip_idgt2lt/trip_idgt
- ltorigingtBOSlt/origingt
- ltdestinationgtARUlt/destinationgt
- lthotelgtGrand Hyatt Arubalt/hotelgt
- ltarrival_dategt2000-05-01lt/arrival_dategt
- ltdaysgt7lt/daysgt
- ltpricegt2200lt/pricegt
- lt/tripgt
- lt/tripsgt
14Presentation 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
15XML 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
16XML 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
17Simple API for XML (SAX)
- Event-driven interface to XML parsers
- org. xml. sax. package
Event
lt?xml version"1.0" ?gt lttripgt lt/tripgt
Event
SAX
Event
18Document 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
lt?xml version"1.0" ?gt lttripgt lt/tripgt
DOM
19Creating TripListXML.jspDemo
Tour Operator
ltTripListgtlt/TripListgt
Travel Agent
TripList.xmlTripList.xsl
ltTripListgtlt/TripListgt
Tour Operator
20Summary