Computer Science E-259 XML with Java, Java Servlet, and JSP
Lecture 13: Conclusion 7 January 2008 David J. Malan
[email protected]
1 Copyright © 2008, David J. Malan
. All Rights Reserved.
Last Time Ajax at HBS
JDOM http://www.jdom.org/
JXPath http://jakarta.apache.org/commons/jxpath/
XMLHttpRequest
Yahoo! UI Library http://developer.yahoo.com/yui/
2 Copyright © 2008, David J. Malan . All Rights Reserved.
JDOM Versus DOM
3
JDOM Document doc = new Document(); Element e = new Element("root"); e.setText("This is the root"); doc.addContent(e);
DOM DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElement("root"); Text text = doc.createText("This is the root"); root.appendChild(text); doc.appendChild(root);
Excerpted from http://www.servlets.com/speaking/jdom-javaone.pdf.
Copyright © 2008, David J. Malan . All Rights Reserved.
JXPath Versus Plain Ol’ Java
4
JXPath Address address = (Address)JXPathContext.newContext(vendor). getValue("locations[address/zipCode='90210']/address");
Plain Ol’ Java Address address = null; Collection locations = vendor.getLocations(); Iterator it = locations.iterator(); while (it.hasNext()){ Location location = (Location)it.next(); String zipCode = location.getAddress().getZipCode(); if (zipCode.equals("90210")){ address = location.getAddress(); break; } }
Excerpted from http://jakarta.apache.org/commons/jxpath/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XMLHttpRequest History
5
The XMLHttpRequest Object is a Working Draft since 10/07. “The XMLHttpRequest Object specification defines an API that provides scripted client functionality for transferring data between a client and a server.”
Excerpted from http://www.w3.org/TR/XMLHttpRequest/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XMLHttpRequest Methods
abort getAllResponseHeaders getResponseHeader open send setRequestHeader
6 Copyright © 2008, David J. Malan . All Rights Reserved.
XMLHttpRequest Properties
onreadystatechange readyState responseText responseXML status statusText
7 Copyright © 2008, David J. Malan . All Rights Reserved.
Computer Science E-259 This Time
XForms 1.0 (Third Edition) XLink 1.0 XPointer 1.0 XInclude 1.0 (Second Edition) XML Base XML Encryption XML Key Management 2.0 XML Signature Data Modeling Computer Science E-259
8 Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) History
9
XForms 1.0 (Third Edition) is a Recommendation since 10/07. “XForms is an XML application that represents the next generation of forms for the Web. By splitting traditional XHTML forms into three parts—XForms model, instance data, and user interface—it separates presentation from content, allows reuse, gives strong typing—reducing the number of round-trips to the server, as well as offering device independence and a reduced need for scripting.” “XForms is not a free-standing document type, but is intended to be integrated into other markup languages, such as XHTML or SVG.”
Excerpted from http://www.w3.org/TR/xforms/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) What
10
Successor of HTML forms Separate data from presentation Use XML to define forms Use XML to transport data Device-independent
Adapted from http://www.w3schools.com/xforms/xforms_intro.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) XHTML Example
11
Adapted from http://www.w3schools.com/xforms/xforms_xhtml.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) XHTML Example
12
Excerpted from http://www.w3schools.com/xforms/xforms_xhtml.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) XForms Example ..... ........ ..... ...
13
Adapted from http://www.w3schools.com/xforms/xforms_xhtml.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) XForms Example ... Select Payment Method Cash Credit Credit Card Number Expiration Date Submit
14
Adapted from http://www.w3schools.com/xforms/xforms_xhtml.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XForms 1.0 (Third Edition) Processing Credit 1235467789012345 2001-08
15
Excerpted from http://www.w3schools.com/xforms/xforms_xhtml.asp.
Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 History
16
XML Linking Language (XLink) Version 1.0 is a recommendation since 6/01 "This specification defines the XML Linking Language (XLink), which allows elements to be inserted into XML documents in order to create and describe links between resources. It uses XML syntax to create structures that can describe links similar to the simple unidirectional hyperlinks of today's HTML, as well as more sophisticated links." Influenced by HTML HyTime (ISO/IEC 10744-1992) Text Encoding Initiative (TEI) Guidelines
Excerpted from http://www.w3.org/TR/xlink/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Goals
17
Assert linking relationships among more than two resources Associate metadata with a link Express links that reside in a location separate from the linked resources
Excerpted from http://www.w3.org/TR/xlink/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Simple Links
18
Excerpted from http://www.w3.org/TR/xlink/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Simple Links This is CSCI E-259.
19 Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Simple Links Dave Matthews
20 Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Attributes of Simple Links
xlink:type Specifies link's type. xlink:href URL of target resource. xlink:title Link's title. xlink:role Target's role. xlink:arcrole Relationship between source and target. xlink:actuate Defines moment of actuation. Must be none, onLoad, onRequest, or other. xlink:show Defines behavior of link upon actuation. Must be embed, new, none, other, or replace.
21 Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Simple Links ]>
"http://www.w3.org/1999/xlink" "simple"
22 Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Extended Links
23
Excerpted from http://www.w3.org/TR/xlink/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XLink 1.0 Extended Links ]>
24 Copyright © 2008, David J. Malan . All Rights Reserved.
XPointer History
XPointer is specified by three recommentations as of 3/03 "This specification defines the XML Pointer Language (XPointer) Framework, an extensible system for XML addressing that underlies additional XPointer scheme specifications. The framework is intended to be used as a basis for fragment identifiers for any resource whose Internet media type is one of text/xml, application/xml, text/xml-external-parsedentity, or application/xml-external-parsedentity. Other XML-based media types are also encouraged to use this framework in defining their own fragment identifier languages."
25 Copyright © 2008, David J. Malan . All Rights Reserved.
XPointer Why, what, and how?
An extension of XPath which is used by XLink to locate remote link resources Relative addressing: allows links to places with no anchors Flexible and robust: XPointer/XPath expressions often survive changes in the target document Can point to substrings in character data and to whole tree fragments URI ----------------------------------------------------------------/ \ http://www.foo.org/bar.xml#xpointer(article/section[position()<=5]) | \ /| | ---------------------------- | \ XPointer expression / \ / ----------------------------------XPointer fragment identifier
26
Excerpted from http://www.w3.org/TR/xquery/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XPointer Points
point(1.0) is just inside the beginning of the p element point(1.2) is between the end of the em element and the following text node (which contains "world.") point(.0) immediately precedes the
root node point(1/2/1.1)
immediately following the "b" in the middle text node
27
Image and examples excerpted from http://www.w3c.org/TR/xptr-xpointer/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XInclude 1.0 (Second Edition) History
28
XML Inclusions (XInclude) Version 1.0 (Second Edition) is a recommendation since 11/06 "Many programming languages provide an inclusion mechanism to facilitate modularity. Markup languages also often have need of such a mechanism. This specification introduces a generic mechanism for merging XML documents (as represented by their information sets) for use by applications that need such a facility."
Excerpted from http://www.w3.org/TR/xinclude/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XInclude 1.0 (Second Edition) Example
29 Copyright © 2008, David J. Malan . All Rights Reserved.
XML Base History
30
XML Base is a recommendation since 6/01 "This document proposes a facility, similar to that of HTML BASE, for defining base URIs for parts of XML documents."
Excerpted from http://www.w3.org/TR/xmlbase/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XML Base With XLink 1.0 and XInclude 1.0
XLink 1.0
J.K. Rowling
XInclude 1.0
31 Copyright © 2008, David J. Malan . All Rights Reserved.
XML Encryption History
32
XML Encryption (Syntax and Processing) is a Recommendation since 12/02. “This document specifies a process for encrypting data and representing the result in XML. The data may be arbitrary data (including an XML document), an XML element, or XML element content. The result of encrypting data is an XML Encryption element which contains or references the cipher data.”
Excerpted from http://www.w3.org/TR/xmlenc-core/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XML Encryption Example John Smith 4019 2445 0277 5567 Bank of the Internet 04/02
33
John Smith A23B45C56 Bank of the Internet 04/02 Excerpted from http://www-106.ibm.com/developerworks/xml/library/s-xmlsec.html/. Copyright © 2008, David J. Malan . All Rights Reserved.
XML Key Management 2.0 History
34
XML Key Management 2.0 is a Recommendation in two parts since 6/05 “This document specifies protocols for distributing and registering public keys, suitable for use in conjunction with the W3C Recommendations for XML Signature and XML Encryption. ”
Excerpted from http://www.w3.org/TR/xkms2/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XML Key Management 2.0 Request
35
KeyValue MIICEDCCAX2gAwIBAgIQimXeUAxYJbJMady9vV1bLjAJBgUrDg MCHQUAMBIxEDAOBgNVBAMTB1Rl c3QgQ0EwHhcNMDMwODE1MDcwMDAwWhcNMDUwODE1MDY1OTU5WjArMSkwJwYDVQQDEyBBbGljZSBB YXJkdmFyayBPPUFsaWNlIENvcnAgQz1VUzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0nIs mR+aVW2egl5MIfOKy4HuMKkk9AZ/IQuDLVPlhzOfgngjVQCjr8uvmnqtNu8HBupui8LgGthO6U9D 0CNT5mbmhIAErRADUMIAFsi7LzBarUvNWTqYNEJmcHsAUZdrdcDrkNnG7SzbuJx+GDNiHKVDQggP BLc1XagW20RMvokCAwEAAaNWMFQwDQYDVR0KBAYwBAMCBkAwQwYDVR0BBDwwOoAQAaVOkaVLLKoF mLN37pC8uqEUMBIxEDAOBgNVBAMTB1Rlc3QgQ0GCEC4MndUXjPG1TZxVKg+HutAwCQYFKw4DAh0F AAOBgQABU91ka7IlkXCfv4Zh2Ohwgg2yObtY3+6C/BTFGrOEBJDy+DoxJ/NuBF18w3rrrR18xE6j NKYLCQb8zUGk4QOG5Y+HT/QTTFvWkiOLXcpTuhnOhXatr42FoYpDkjx2QWK+J5Q2l/Rgjgc/0ZV8 U/kD8UuRkXp4AZh7QsiX8AcO0w== Signature KeyName KeyValue X509Cert X509Chain PGPWeb PGP Encryption Excerpted from http://www.w3.org/TR/xkms2/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XML Signature History
36
XML Signature is a Recommendation since 2/02. “This document specifies XML digital signature processing rules and syntax. XML Signatures provide integrity, message authentication, and/or signer authentication services for data of any type, whether located within the XML that includes the signature or elsewhere.”
Excerpted from http://www.w3.org/TR/xmldsig-core/.
Copyright © 2008, David J. Malan . All Rights Reserved.
XML Signature Example
37
j6lwx3rvEPO0vKtMup4NbeVu8nk= MC0CFFrVLtRlk=... ...
...
...... Excerpted from http://www-106.ibm.com/developerworks/xml/library/s-xmlsec.html/. Copyright © 2008, David J. Malan . All Rights Reserved.
Data Modeling Loose Guidelines
The intricacies of effective data modeling is impossible to teach in a few slides, but… Here are a few loose guidelines when designing data models Avoid repeating data in your XML document If there are relationships between objects in your data, express this with a reference
38
... ... ... Harrison Ford ... Copyright © 2008, David J. Malan . All Rights Reserved.
Data Modeling Loose Guidelines
Don't fall into relational "hacks": use XML as it was designed to be used If you come from the relational database world, you may be accustomed to representing an address with several numbered fields address1, address2, address3, city, state Don't do this in XML! Instead, ... ... ... ... ...
39 Copyright © 2008, David J. Malan . All Rights Reserved.
Data Modeling Loose Guidelines
When creating a new field for an element, always ask yourself whether it should be a child element or an attribute If the field is tightly bound with the parent element and is just a simple string (e.g., an id or name), consider making it an attribute If the field has any structure or complexity (or you can foresee extending it to have such), make it a child element Think of a Java class: is the member a String, or a reference to another class object?
40 Copyright © 2008, David J. Malan . All Rights Reserved.
CSCI E-75: Building Dynamic Websites http://www.computerscience75.org/ “Today's websites are increasingly dynamic. Pages are no longer static HTML files but instead generated by scripts and database calls. User interfaces are more seamless, with technologies like Ajax replacing traditional page reloads. This course teaches students how to build dynamic websites with Ajax and with Linux, Apache, MySQL, and PHP (LAMP), one of today's most popular frameworks. Students learn how to set up domain names with DNS, how to structure pages with XHTML and CSS, how to program in JavaScript and PHP, how to configure Apache and MySQL, how to design and query databases with SQL, and how to use Ajax with both XML and JSON. The course discusses issues of security, scalability, and cross-browser support.”
41 Copyright © 2008, David J. Malan . All Rights Reserved.
Computer Science E-259
“XML is beautiful, but as with beautiful people, it is neither easy to get along with nor quick.” “XML’s strength is its wide adoption and excellent tools. XML itself is not that exciting.”
42 Copyright © 2008, David J. Malan . All Rights Reserved.
Computer Science E-259 Goals of the Course
Cut through the hype and get to the value Focus on practicality: what you need to know to do real work applications: what are the tools and technologies necessary to put XML to use possibilities: what are some of the most common ways XML is being used in applications Emphasize understanding from the bottom up
43 Copyright © 2008, David J. Malan . All Rights Reserved.
Computer Science E-259 Rewards of the Course
A solid understanding of XML, the syntax, data structures, and algorithms that surround it Xperience DTD, SVG, XForms, XInclude, XLink, XML Base, XML Encryption, XML Key Management, XML Namespaces, XML Schema, XML Signature, XPath, XPointer, XQuery, XSL-FO, and XSLT SAX and DOM JAXP and TrAX JavaServer Pages and Java Servlet HTTP, SOAP, web services, WSDL FOP, Stylus Studio, Tomcat, Xalan, Xerces, XMLSpy...
44 Copyright © 2008, David J. Malan . All Rights Reserved.
Computer Science E-259 XML with Java, Java Servlet, and JSP
Lecture 13: Conclusion 7 January 2008 David J. Malan malan@post.harvard.edu
45 Copyright © 2008, David J. Malan . All Rights Reserved.