Post on 30-May-2018
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 1/31
XML AND XHTMLContent Versus Appearance
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 2/31
XML Basics
XML is the basic building block of Web services. All the Web
services technologies specified by the WS-I Basic Profile 1.0are built on XML and the W3C XML Schema Language.
The extensible Markup Language (XML) is a meta-language
or a language for defining other languages defined by aspecification.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 3/31
XML Address Document<?xml version="1.0" encoding="UTF-8" ?>
<addresses>
<address category="friend">
<name>Bill Frankenfiller</name> <street>3243 West 1st Ave.</street>
<city>Madison</city> <state>WI</state> <zip>53591</zip>
</address>
<address category="business">
<name>Amazon.com</name>
<street>1516 2nd Ave</street>
<city>Seattle</city> <state>WA</state> <zip>90952</zip></address>
</addresses>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 4/31
Widescreen Graphics
XML Document Instance
<?xml version="1.0" encoding="UTF-8" ?>
<address><name>Amazon.com</name>
<street>1516 2nd Ave</street>
<city>Seattle</city>
<state>WA</state>
<zip>90952</zip></address>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 5/31
XML Declaration
Elements Attributes
Empty-Element Tag in XML
Comments CDATA Section
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 6/31
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This document contains address information -->
<address category="business" >
<name>Amazon.com</name>
<street>1516 2nd Ave</street>
<city>Seattle</city>
<state>WA</state>
<zip>90952</zip>
<note><![CDATA[ <html><body><p>Last time I contacted <b> text <body></html>
]]>
</note>
</address>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 7/31
Processing XML Documents
XML parser
parsers read a stream of data (usually a file or networkstream) and break it down into functional units that can
then be processed by a software application.
basically two standard kinds of XML parser APIs: SAX
and DOM.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 8/31
Processing XML Documents
SAX (Simple API for XML)
first standard XML parser API and is very popular.Although several individuals created it, David Brownellcurrently maintains SAX2, the latest version, as anopen development project at SourceForge.org. SAX2parsers are available in many programminglanguages including Java. SAX2 is based on an eventmodel.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 9/31
Processing XML Documents
DOM (Document Object Model
was developed after SAX2 and maintained by the W3C. DOMlevel 2 (DOM 2) is the current version, but there is a DOM level3 in the works. DOM 2 parsers are also available for manyprogramming languages, including Java. DOM 2 presents theprogrammer with a generic, object-oriented model of an XML
document. Elements, attributes, and text values are representedas objects organized into a hierarchical tree structure thatreflects the hierarchy of the XML document being processed
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 10/31
XML Namespaces
An XML namespace provides a qualified name for an
XML element or attribute
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 11/31
XML Namespaces<?xml version="1.0" encoding="UTF-8" ?>
<purchaseOrder orderDate="2003-09-22µ xmlns="http://www.Monson-Haefel.com/jwsbook/PO">
<accountName>Amazon.com</accountName>
<accountNumber>923</accountNumber>
<address xmlns="http://www.Monson-Haefel.com/jwsbook/ADDR">
<name>AMAZON.COM</name>
<street>1850 Mercer Drive</street>
<city>Lexington</city>
<state>KY</state>
<zip>40511</zip>
</address>
<book> <title>J2EE Web Services</title> <quantity>300</quantity> <wholesale-
price>29.99</wholesale-price> </book>
<total>8997.00</total>
</purchaseOrder>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 12/31
XML Namespaces
Default Namespaces
The xmlns declarations made in last example defined the default
namespace for the element and all its descendants. The scope of adefault namespace applies only to the element and its descendants, sothe xmlns used in the address element applies only to the address,name, street, city, state, and zip elements. The default xmlns declared inthe purchaseOrder element applies to all the elements except theaddress elements, because the address element overrides the default
namespace of the purchaseOrder element to define its own defaultnamespace.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 13/31
XML Namespaces
Prefixes
You can assign an XML namespace to a prefix, then usethat prefix to fully qualify each element name.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 14/31
XML Namespaces<?xml version="1.0" encoding="UTF-8" ?>
<po:purchaseOrder orderDate="2003-09-22´ xmlns:po="http://www.Monson-Haefel.com/jwsbook/POµxmlns:addr="http://www.Monson-Haefel.com/jwsbook/ADDR">
<po:accountName>Amazon.com</po:accountName>
<po:accountNumber>923</po:accountNumber>
<addr:address>
<addr:name>AMAZON.COM</addr:name>
<addr:street>1850 Mercer Drive</addr:street>
<addr:city>Lexington</addr:city>
<addr:state>KY</addr:state>
<addr:zip>40511</addr:zip>
</addr:address>
<po:book>
<po:title>J2EE Web Services</po:title>
<po:quantity>300</po:quantity>
<po:wholesale-price>29.99</po:wholesale-price>
</po:book>
<po:total>8997.00</po:total>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 15/31
XML Namespaces
XML namespaces based on URLs tend to be universally
unique, which makes it easy for parsers and softwareapplications to distinguish between instances of
different markup languages within the same document.
Namespaces help avoid name collisions, where two
elements from different markups share a common localname.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 16/31
Avoiding Element Name Collisions<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="Address-Updateµ targetNamespace="http://www.monson-haefel.org/jwsbook/Address-Update"
xmlns:tns="http://www.monson-haefel.org/jwsbook/Address-Update"
xmlns:addr="http://www.Monson-Haefel.com/jwsbook/ADDR"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns=http://schemas.xmlsoap.org/wsdl/> ...
<!-- message elements describe the paramters and return values -->
<message name="AddressMessage">
<part name="address" element="addr:address" />
</message>...
<!-- service tells us the Internet address of a Web service -->
<service name="AddressUpdateService">
<documentation>Update a customers mailing address</documentation>
<port name="AddressUpdate_Port" binding="tns:AddressUpdate_Binding">
<soap:address location="http://www.monson-haefel.org/jwsbook/BookPrice" />
</port>
</service> </definitions>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 17/31
XML parsers and other tools can use XML namespaces
to process, sort, and search XML elements in a
document according to their QNames. This allows
reusable code modules to be invoked for specific
namespaces.
XML namespaces also allow for a great versioningsystem. If the Address Markup changes, we can assign
the new version its own namespace.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 18/31
W3C XML Schema Language
XML Schema Basics
The XML specification includes the Document Type Definition
(DTD), which can be used to describe XML markuplanguages and to validate instances of them (XMLdocuments). While DTDs have proven very useful over theyears, they are also limited. To address limitations of DTDs,
the W3C (World Wide Web Consortium), which managesthe fundamental XML standards, created a new way todescribe markup languages called XML schema.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 19/31
W3C XML Schema Language
Why XML Schema Is Preferred to DTDs in Web Services?
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT address (street+, city, state, zip)>
<!ELEMENT street (#PCDATA) >
<!ELEMENT city (#PCDATA) >
<!ELEMENT state (#PCDATA) ><!ELEMENT zip (#PCDATA) >
<!ATTLIST address category CDATA #REQUIRED >
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 20/31
W3C XML Schema Language
DIFFERENCES DTD'S SCHEMAS
DATA CONSTRAINTS DTD's have minimal data constraints. Schemas allow more specific constraints
USER DEFINED TYPES
DTD's limit to a fixed set of content
models
DTDs don't support types like integer,decimal, Boolean, and enumeration
Schemas provide greater flexibility XML
schema is superior to DTD because it
defines a richer type system, which
includes simple primitives (integer,
double, boolean, among others).
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 21/31
W3C XML Schema Language<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
targetNamespace="http://www.Monson-Haefel.com/jwsbook">
<element name="address" type="mh:USAddress" />
<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType>
...
</schema>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 22/31
The XML Schema Document
A schema describes the structure of an XML document
in terms of complex types and simple types. Complex types describe how elements are organized
and nested
. Simple types are the primitive data types contained
by elements and attributes.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 23/31
The XML Schema Document<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
targetNamespace="http://www.Monson-Haefel.com/jwsbook">
<element name="address" type="mh:USAddress" />
<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType> ...
</schema>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 24/31
Simple Types
, a simple element type will not contain other
elements; it will contain only data. .The XML schema specification defines many standard
simple types.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 25/31
XML Schema Built-in Simple Types Java Primitive Types
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns=http://www.w3.org/2001/XMLSchema
xmlns:mh=http://www.Monson-Haefel.com/jwsbook
targetNamespace="http://www.Monson-Haefel.com
/jwsbook">
...
<complexType name="PurchaseOrder">
<sequence><element name="accountName" type="string" />
<element name="accountNumber" type="integer´ >
<element name="total´ type="float" />
<!-- More stuff follows -->
</sequence>
</complexType>
...
</schema>
package com.monsonhaefel.jwsbook;
public class PurchaseOrder
{
String accountName;
int accountNumber;
float total;
// more stuff follows}
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 26/31
XML Schema Built-in Simple Types
Simple Type Definition
string A sequence of characters conforming to UCS
normalizedString A string without carriage returns, line feeds, or tabs
token A string without spaces, line feeds, or tabs
NMTOKEN A token used in attributes
byte A non-decimal number between ±128 and 127
unsignedByte A non-decimal number between 0 and 255
base64Binary Base64-encoded binary data (RFC 2045)[a]
hexBinary Hex-encoded binary data[b]
integer A base-10-integer number of any size («)[c]
positiveInteger A base-10 integer greater then zero (1, 2, «)
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 27/31
XML Schema Built-in Simple Types
Simple Type Definition
negativeInteger A base-10 integer less then zero («, ±2, ±1)
int A base-10 integer between ±2,147,483,648 and 2,147,483,647 (±2 billion and 2
billion)
unsignedInt A base-10 integer between 0 and 4,294,967,295 (zero and 4 billion)
long A base-10 integer between ±9,223,372,036,854,775,808 and
9,223,372,036,854,775,807 (±9 quintillion and 9 quintillion)
unsignedLong A base-10 integer between 0 and 18,446,744,073,709,551,615 (zero and 18
quintillion)
short A base-10 integer between ±32,767 and 32,767
unsignedShort A base-10 integer between 0 and 65,535
decimal A decimal number of any precision and size
float A decimal number conforming to the IEEE single-precision 32-bit floating-point
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 28/31
XML Schema Built-in Simple Types
Simple Type Definition
boolean A boolean value of "true" or "false"
You can also use the values of "0" (false) or "1" (true); either convention is fine.
time A time in hours, minutes, seconds, and milliseconds formatted as hh:mm:ss.sss (e.g.,
1:20 PM is 13:20:00)
You may include the optional Coordinated Universal Time (UTC) designator (e.g.,
1:20 PM Eastern Standard Time (EST) is 13:20:00-05:00)[e]
date A Gregorian date in centuries, years, months, and days (e.g., December 31, 2004 is
2004-12-31)[e]
dateTime A Gregorian date measured in centuries, years, months, and days, with a time fieldset off by a T (e.g., 1:20 PM EST on December 31, 2004 would be 2004-12-
31T13:20:00-05:00)[e]
duration A span of time measured in years, months, days, and seconds (e.g., 1 year, 2 months,
3 days, 10 hours, and 30 minutes would be P1Y2M3DT10H30M)
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 29/31
Complex Types complex types define how elements that contain other elements are
organized.
<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType>
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 30/31
Complex Types
Sequences of Elements :complexType declarations in
schemas will contain a sequence element that lists one
or more element definitions. The element definitions
tell you which elements are nested in the type, the
order in which they appear, and the kind of data
each element contains.
8/9/2019 XML and XHTML Content Versus Appearance
http://slidepdf.com/reader/full/xml-and-xhtml-content-versus-appearance 31/31
Mapping a Schema Complex Type to an XML Element
XML Schema: USAddress XML Document: address
<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" /><element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType>
<address>
<name>Amazon.com</name>
<
street>1516 2nd Ave<
/street><city>Seattle</city>
<state>WA</state>
<zip>90952</zip>
</address>