0% found this document useful (0 votes)
62 views31 pages

XML and XHTML Content Versus Appearance

XML is a meta-language used to define other languages. It allows for structuring and tagging of data with elements and attributes. XML documents can be validated against an XML schema. Schemas provide stronger validation of elements and data types compared to older DTDs. Namespaces are used in XML to avoid element name collisions and allow unique identification of elements.

Uploaded by

contacttoba9948
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views31 pages

XML and XHTML Content Versus Appearance

XML is a meta-language used to define other languages. It allows for structuring and tagging of data with elements and attributes. XML documents can be validated against an XML schema. Schemas provide stronger validation of elements and data types compared to older DTDs. Namespaces are used in XML to avoid element name collisions and allow unique identification of elements.

Uploaded by

contacttoba9948
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

XML AND XHTML

Content Versus Appearance


XML Basics
 XML is the basic building block of Web services. All the Web
services technologies specified by the WS-I Basic Profile 1.0
are 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 a
specification.
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>
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>
 XML Declaration
 Elements
 Attributes
 Empty-Element Tag in XML
 Comments
 CDATA Section
<?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>
Processing XML Documents
 XML parser
parsers read a stream of data (usually a file or network
stream) 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.


Processing XML Documents
 SAX (Simple API for XML)
first standard XML parser API and is very popular.
Although several individuals created it, David Brownell
currently maintains SAX2, the latest version, as an open
development project at SourceForge.org. SAX2 parsers
are available in many programming languages including
Java. SAX2 is based on an event model.
Processing XML Documents
 DOM (Document Object Model
was developed after SAX2 and maintained by the W3C. DOM
level 2 (DOM 2) is the current version, but there is a DOM level 3
in the works. DOM 2 parsers are also available for many
programming languages, including Java. DOM 2 presents the
programmer with a generic, object-oriented model of an XML
document. Elements, attributes, and text values are represented as
objects organized into a hierarchical tree structure that reflects the
hierarchy of the XML document being processed
XML Namespaces
 An XML namespace provides a qualified name for an
XML element or attribute
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>
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 a default
namespace applies only to the element and its descendants, so the xmlns
used in the address element applies only to the address, name, street, city,
state, and zip elements. The default xmlns declared in the purchaseOrder
element applies to all the elements except the address elements, because
the address element overrides the default namespace of the
purchaseOrder element to define its own default namespace.
XML Namespaces
Prefixes
You can assign an XML namespace to a prefix, then use
that prefix to fully qualify each element name.
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>
</po:purchaseOrder>
XML Namespaces
 XML namespaces based on URLs tend to be
universally unique, which makes it easy for parsers
and software applications 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 local name.
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>
 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 versioning
system. If the Address Markup changes, we can
assign the new version its own namespace.
W3C XML Schema Language
 XML Schema Basics
The XML specification includes the Document Type
Definition (DTD), which can be used to describe XML
markup languages and to validate instances of them (XML
documents). While DTDs have proven very useful over the
years, they are also limited. To address limitations of
DTDs, the W3C (World Wide Web Consortium), which
manages the fundamental XML standards, created a new
way to describe markup languages called XML schema.
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 >
W3C XML Schema Language
DIFFERENCES DTD'S SCHEMAS

DATA CONSTRAINTS DTD's have minimal data constraints. Schemas allow more specific constraints

Schemas provide greater flexibility XML


DTD's limit to a fixed set of content
schema is superior to DTD because it
models
USER DEFINED TYPES defines a richer type system, which
DTDs don't support types like integer,
includes simple primitives (integer,
decimal, Boolean, and enumeration
double, boolean, among others).
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>
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.
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>
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.
XML Schema Built-in Simple Types Java Primitive Types

<?xml version="1.0" encoding="UTF-8"?> package com.monsonhaefel.jwsbook; 


<schema xmlns=http://www.w3.org/2001/XMLSchema public class PurchaseOrder
xmlns:mh=http://www.Monson-Haefel.com/jwsbook {
targetNamespace="http://www.Monson-Haefel.com
  String accountName;
int accountNumber;
/jwsbook">
float total;
... // more stuff follows 
<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>
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, …)


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
type
double A decimal number conforming to the IEEE double-precision 64-bit floating-point
type
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 field
set 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)
  Duration may be negative, and zero values can be left off (e.g., 120 days earlier is
P120D). The value must always start with the letter P. [f]
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>
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.
Mapping a Schema Complex Type to an XML Element

XML Schema: USAddress XML Document: address

<complexType name="USAddress">
<sequence> <address>
<element name="name" type="string" /> <name>Amazon.com</name>
<street>1516 2nd Ave</street>
<element name="street" type="string" />
<city>Seattle</city>
<element name="city" type="string" /> <state>WA</state>
<element name="state" type="string" /> <zip>90952</zip>
<element name="zip" type="string" /> </address>
</sequence>
</complexType>

You might also like