SlideShare uma empresa Scribd logo
1 de 230
Baixar para ler offline
IT6801 SERVICE ORIENTED ARCHITECTURE L T P C
3 0 0 3
OBJECTIVES:
The student should be made to:
 Learn XML fundamentals.
 Be exposed to build applications based on XML.
 Understand the key principles behind SOA.
 Be familiar with the web services technology elements for realizing SOA.
 Learn the various web service standards.
UNIT I INTRODUCTION TO XML 9
XML document structure – Well formed and valid documents – Namespaces – DTD – XML
Schema –X-Files.
UNIT II BUILDING XML- BASED APPLICATIONS 9
Parsing XML – using DOM, SAX – XML Transformation and XSL – XSL Formatting –
Modeling Databases in XML.
UNIT III SERVICE ORIENTED ARCHITECTURE 9
Characteristics of SOA, Comparing SOA with Client-Server and Distributed architectures –
Benefits of SOA -- Principles of Service orientation – Service layers.
UNIT IV WEB SERVICES 9
Service descriptions – WSDL – Messaging with SOAP – Service discovery – UDDI –
Message Exchange Patterns – Orchestration – Choreography –WS Transactions.
UNIT V BUILDING SOA-BASED APPLICATIONS 9
Service Oriented Analysis and Design – Service Modeling – Design standards and
guidelines -- Composition – WS-BPEL – WS-Coordination – WS-Policy – WS-Security –
SOA support in J2EE.
TOTAL PERIOD: 45 Periods
OUTCOMES:
Upon successful completion of this course, students will be able to:
 Build applications based on XML.
 Develop web services using technology elements.
 Build SOA-based applications for intra-enterprise and inter-enterprise applications.
TEXTBOOKS:
1. Ron Schmelzer et al. “XML and Web Services”, Pearson Education, 2002
2. Thomas Erl, “Service Oriented Architecture: Concepts, Technology, and Design”,
Pearson Education, 2005.
REFERENCES:
1. Frank P.Coyle, “XML, Web Services and the Data Revolution”, Pearson Education,
2002.
2. Eric Newcomer, Greg Lomow, “Understanding SOA with Web Services”, Pearson
Education, 2005.
3. Sandeep Chatterjee and James Webber, “Developing Enterprise Web Services: An
Architect's Guide”, Prentice Hall, 20044.
4. James McGovern,Sameer Tyagi, Michael E.Stevens, Sunil Mathew, ”Java Web.
Services Architecture”, Morgan Kaufmann Publishers, 2003.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 1
S.No. Name of the Topic Reference Book (Text Book)
UNIT I - INTRODUCTION TO XML
1. XML document structure Chapter 2 (Text 1)
2. Well-formed and valid documents Chapter 2 (Text 1)
3. Namespaces Chapter 2 (Text 1)
4.
DTD Chapter 3 (Text 1)
5.
6.
XML Schema Chapter 4 (Text 1)
7.
8.
X-Files Chapter 5 (Text 1)
9.
Content Beyond Syllabus JSON
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 2
XML (Extensible Markup Language)
XML is a simple, very flexible text format derived from SGML. Originally designed to meet the
challenges of large-scale electronic publishing, XML is also playing an increasingly important
role in the exchange of a wide variety of data on the Web and elsewhere.
Common Uses/Applications of XML
 Data Interchange Format
Because XML is nonproprietary and easy to read and write, it’s an excellent format for the
interchange of data among different applications.
Alternative Technologies: JSON (JavaScript Object Notation), YAML
 Web development
Web documents can be created from XML using XSLT to transform the documents into HTML.
 Documentation (or) Document Publishing
The term publishing refers to converting a document from a text file that contains XML markup
to one or more output files in a specific presentation format, such as HTML, Portable Document
Format (PDF), PostScript, Rich Text Format (RTF), and so on.
(eg): DocBook (XML vocabulary for representing document contents)
 Database Development
 Configuration Files
Configuration files, or config files configure the parameters and initial settings for some
computer programs. They are used for user applications, server processes and operating system
settings. (eg): web.xml
 Web Services
Advantages of XML
 Simplicity
 Extensibility
 Interoperability
 Openness
 Self-describing
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 3
Drawbacks of XML
XML takes up lots of space (3 to 20 times more) to represent data that could be similarly
modeled using a binary format or a simpler text file format. It’s the price we pay for human-
readable, platform-neutral, process-separated, metadata-enhanced, structured, validated code. It’s
possible that 1GB of database information can result in over 20GB of XML-encoded
information.
Introduction to XML
Markup Language
The main concept behind markup languages is that they use special text strings to surround data
or text with information that indicates the context, meaning, or interpretation of the data
encapsulated in the markup. In effect, markup languages in general and XML in particular really
contain only two kinds of information: markup elements and actual data that are given meaning
by these markup elements. Together, these are known as XML text.
Markup text has a couple rules. First, it needs to be differentiated from the rest of the document
text by a unique set of characters that delineates where the markup information starts and ends.
These special characters are known as delimiters.
Character Meaning
< The start of an XML markup tag
> The end of an XML markup tag
& The start of an XML entity
; The end of an XML entity
Table: XML Delimiter Characters
Extensible
Extensibility, as applied to XML, is the ability for the language to be used to define specific
vocabularies and metadata. Rather than being fixed in describing a particular set of data, XML,
in conjunction with its DTDs and schema, is able to define any number of documents that
together form a language of their own. It would be a difficult proposition at best to add a new set
of information to a text file or relational database management system (RDBMS). XML files,
especially those created using an “open content model,” can easily be extended by adding
additional elements and attributes.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 4
XML Document Structure
The major portions of an XML document include the following:
 The XML declaration
 The Document Type Declaration
 The element data
 The attribute data
 The character data or XML content
XML Declaration
The first part of an XML document is the declaration. The XML declaration is a processing
instruction of the form <?xml ...?>. Although it is not required, the presence of the
declaration explicitly identifies the document as an XML document and indicates the version
of XML to which it was authored. In addition, the XML declaration indicates the presence of
external markup declarations and character encoding.
The standalone document declaration defines whether an external DTD will be processed as part
of the XML document. When standalone is set to “yes”, only internal DTDs will be allowed.
When it is set to “no”, an external DTD is required and an internal DTD becomes an optional
feature
<?xml version=“1.0” standalone=“yes” ?>
<?xml version=“1.0” standalone=“no” ?>
<?xml version=“1.0” encoding=“UTF-8” standalone=“yes” ?>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 5
Document Type Declaration
The Document Type Declaration (DOCTYPE) gives a name to the XML content and
provides a means to guarantee the document’s validity, either by including or specifying a
link to a Document Type Definition (DTD).
General Forms of the Document Type Declarations
<!DOCTYPE NAME SYSTEM “file”>
<!DOCTYPE NAME SYSTEM [ ]>
<!DOCTYPE NAME SYSTEM “file” [ ]>
In the first form listed, the DOCTYPE is referring to a document that only allows use of an
externally defined DTD subset. The second declaration only allows an internally defined
subset within the document. The final listing provides a place for inclusion of an internally
defined DTD subset between the square brackets while also making use of an external subset.
In the preceding listing, the keyword NAME should be replaced with the actual root element
contained in the document, and the “file” keyword should be replaced with a path to a valid
DTD.
Markup and Content
In general, six kinds of markup can occur in an XML document: elements, entity references,
comments, processing instructions, marked sections, and Document Type Declarations.
 Elements
Within an XML document, elements are the most common form of markup. XML elements
are either a matched pair of XML tags or single XML tags that are “self-closing.” Matching
XML tags consist of markup tags that contain the same content, except that the ending tag is
prefixed with a forward slash.
<regno> Opening Tag / Start Tag
</regno> Closing Tag / End Tag
When elements do not come in pairs, the element name is suffixed by the forward slash.
These “unmatched” elements are known as empty elements.
<br/> Empty Elements
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 6
 Attributes
Attributes are name/value pairs contained within the start element that can specify text
strings that modify the context of the element.
<studentName section =“A”>Rahul</studentName>
 Entity References
Entities provide a means to indicate to XML-processing applications that a special text string
is to follow that will be replaced with a different literal value.
CHARACTER REFERENCE
& &amp;
< &lt;
> &gt;
“ &quot;
‘ &apos;
Table: Built-in Entity References
<description>The following says that 8 is greater than5
</description>
<equation>4 &gt; 5</equation>
 Comments
The character sequence <!-- begins a comment and --> ends the comment. Comments can be
placed anywhere in a document and are not considered to be part of the textual content of an
XML document. As a result, XML processors are not required to pass comments along to an
application.
<!-- This XML document describes student information -->
 Processing Instructions
Processing instructions (PIs) are like comments that are intended for computer programs
reading the document. However, XML parsers are required to pass along the contents of
processing instructions to the application on whose behalf they’re parsing, unlike comments
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 7
that a parser is allowed to silently discard. However, the application that receives the
information is free to ignore any processing instruction it doesn’t understand.
Processing instructions begin with <? and end with ?>. The starting <? is followed by an
XML name called the target, which identifies the program that the instruction is intended for,
followed by data for that program. Processing instructions have the following form:
<?target data?>
Eg: <?xml-stylesheet type=”text/xsl” href=”appUsers.xslt” ?>
The target in this example is xml-stylesheet.
 CDATA
CDATA stands for Character Data. CDATA sections provide a way to tell the parser that
there is no markup in the characters contained by the CDATA section. This makes it much
easier to create documents containing sections where markup characters might appear, but
where no markup is intended. Everything inside a CDATA section is ignored by the parser.
A CDATA section starts with "<![CDATA[" and ends with "]]>":
<example-code>
<![CDATA[
while (x <len&& !done) {
print( "Still working, 'zzzz'." );
++x;
}
]]>
</example-code>
Rules of XML Structure
All XML Elements Must Have a Closing Tag
XML requires all tags to be closed. They can be closed by matching a beginning element tag
with a closing tag, or they can be closed by the use of empty elements. In either case, no tag
may be left unclosed.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 8
Incorrect XML Due to Unclosed Tags
<markup>This is not valid XML
<markup>Since there is no closing tag
XML Tags Are Case Sensitive
In XML, the use of capitalization is incredibly important. XML elements and attributes are
case sensitive. This means that differences in capitalization will be interpreted as different
elements or attributes. In XML, the elements <student> and <Student> are as different as
<egg> and <house>.
All XML Elements Must Have Proper Nesting
XML requires that elements be nested in proper hierarchical order. Tags must be closed in
the reverse order in which they are opened. A proper analogy is to think of XML tags as
envelopes. There must never be a case where one envelope is closed when an envelope
contained within it is still open.
<student>
<regno>
These tags are improperly nested
</student>
</regno>
All XML Documents Must Contain a Single Root Element
XML documents must contain a single root element—no less, and certainly no more. All
other elements in the XML document are then nested within this root element. Once the root
element is defined, any number of child elements can branch off it as long as they follow the
rules.
Attribute Values Must Be Quoted
When attributes are used within XML elements, their values must be surrounded by quotes.
Although most systems accept single or double quotes for attribute values, it is generally
accepted to use double quotes around attribute values.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 9
<?xml version=1.0?>
<shirt>
<price currency=USD>14.99</price>
</shirt>
Incorrect XML Due to Improper Quoting of Attributes
Attributes May Only Appear Once in the Same Start Tag
Even though attributes may be optional, when they are present, they can only appear once.
This simple restriction prevents ambiguity when multiple, conflicting attribute name/value
pairs are present.
<shirt size=”large” size=”small”>Zippy Tee</shirt>
Incorrect XML Due to Multiple Attribute Names in Start Tag
Attribute Values Cannot Contain References to External Entities
Although external entities may be allowed for general markup text, attribute values cannot
contain references to external entities. However, attribute values can make use of internally
defined entities and generally available entities, such as &lt; and &quot;.
All Entities Except amp, lt, gt, apos, and quot Must Be Declared Before They
Are Used
Although this goes without saying, entities cannot be used before they are properly declared.
Referring to an undeclared entity would obviously result in an XML document that is not
well formed and proper. However, there are a number of entities that can be assumed to be
defined by XML processors. So far, these are limited to the entities &amp;, &lt;, &gt;,
&apos;, and &quot;.
Well-Formed XML Document
Well-formed XML document
A XML document is well-formed if it conforms to XML specification and it is syntactically
correct.
Not well-formed:
 An element lacks a closing tag (and is not self-closing).
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 10
 Elements overlap without proper nesting: <a><b></a></b>
 An attribute value is missing a closing quote that matches the opening quote.
 <or& are used in content rather than &lt or &amp;.
 Multiple root elements exist.
 Multiple XML declarations exist, or an XML declaration appears other than at the top of
the document.
XML Processing
XML Parser or Processor is a software module that is used to read XML documents and provide
access to their content and structure.
XML Parser (Validating & Non-Validating)
A non-validating parser is required to verify that an input XML document is well formed or not.
Non-validating parsers have the advantage that they will generally run faster than validating
parsers because they perform less validation.
A validating parser requires that any document it parses contain a DTD or XSD. The validating
parser will read the DTD or XSD, verify that the document conforms with DTD or XSD, and
also verify that the document meets validity constraints defined by the XML recommendation.
An advantage of validating parsers is that every correct implementation of a validating parser
should produce essentially the same results when parsing a given XML document.
XML Vocabulary
An XML vocabulary is created by specifying a complete description of the elements and
attributes for a specific type of XML document.
(Eg) RSS, XSLT, SOAP, SVG etc
XML Namespace
An XML namespace is a collection of element and attribute names associated with a particular
XML vocabulary through an absolute URI known as the namespace name.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 11
Need for XML Namespace
It provides a mechanism to avoid name conflicts when XML document may contain element or
attribute names from more than one XML vocabulary. If each vocabulary is given a namespace,
the ambiguity between identically named elements or attributes can be resolved.
Example
This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
If these XML fragments were added together, there would be a name conflict. Both contain a
<table> element, but the elements have different content and meaning.
Name conflicts in XML can easily be avoided using a name prefix.
<?xml version = "1.0"?>
<!-- Demonstrating namespaces -->
<!--This XML carries information about an HTML table, and a piece of
furniture -->
<h:demo
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 12
xmlns:h = "http://www.w3schools.com/htmlTableInfo"
xmlns:f = "http://www.w3schools.com/furnitureTableInfo">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</h:demo>
In the example above, there will be no conflict because the two <table> elements have different
namespaces.
 xmlns is the attribute used to specify the namespace URI.
 h and f are namespace prefixes
 http://www.w3schools.com/htmlTableInfo
andhttp://www.w3schools.com/furnitureTableInfo are namespace URIs. They are
unique and need not represent actual webpages.
Default Namespace
To eliminate the need to place namespace prefixes in each element, document authors may
specify a default namespace for an element and its children.
<?xml version = "1.0"?>
<!-- Demonstrating Default Namespaces -->
<!-- This XML carries information about an HTML table, and a piece of
furniture -->
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 13
<demo
xmlns = "http://www.w3schools.com/htmlTableInfo"
xmlns:f = " http://www.w3schools.com/furnitureTableInfo">
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</demo>
In the above example, xmlns attribute without namespace prefix specifies default namespace.
XML Schema
An XML Schema is a language for expressing constraints about XML documents. There are
several different schema languages in widespread use, but the main ones are:
 Document Type Definitions (DTDs)
 XSD (XML Schema Definitions)
 Relax-NG
 Schematron
DTD
A document type definition lists the elements, attributes, entities, and notations that can be used
in a document, as well as their possible relationships to one another. A DTD specifies a set of
rules for the structure of a document.
A DTD can be declared inside an XML document or in an external file.
 Internal DTD: DTD is declared inside the XML file.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 14
 External DTD: DTD is declared in an external file.
The Document Type Declaration
A document type declaration begins with <!DOCTYPE and ends with a >. In between is the
name of the root element, followed either by a pair of square brackets containing the DTD itself
or by the SYSTEM keyword and a URL where the DTD can be found (or, occasionally, both). A
document type declaration has this basic form:
<!DOCTYPE rootelement SYSTEM | PUBLIC DTDlocation [
internalDTDelements ] >
 The exclamation mark (!) is used to signify the beginning of the declaration.
 DOCTYPE is the keyword used to denote this as a Document Type Definition.
 rootelement is the name of the root element or document element of the XML document.
 SYSTEM and PUBLIC are keywords used to designate that the DTD is contained in an
external document. Although the use of these keywords is optional, to reference an
external DTD you would have to use one or the other. The SYSTEM keyword is used in
tandem with a URL to locate the DTD. The PUBLIC keyword specifies some public
location that will usually be some application-specific resource reference.
 internalDTDelements are internal DTD declarations. These declarations will always be
placed within opening ([) and closing (]) brackets.
DTD Elements
 Each element in the DTD should be defined with the following syntax:
<!ELEMENT elementname rule >
o ELEMENT is the tag name that specifies that this is an element definition.
o elementname is the name of the element.
o rule is the definition to which the element’s data content must conform.
 Elements are declared using element declarations. Each element declaration gives the
name of the element and lists the elements and text that it can contain. This list is called
the content specification. For example, this element declaration for the firstName element
says that elements with the name firstName must contain only parsed character data:
<!ELEMENT firstName (#PCDATA)>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 15
Every declaration begins with <!. Element declarations begin with <!ELEMENT(case-
sensitive, as most things are in XML). This is followed by some white space and the
name of the element being declared, firstName in this example.
 The content spec (#PCDATA) says that the element must contain parsed character data.
Parsed character data is essentially any text that’s not markup. This also includes entity
references, such as &amp;, that are replaced by text when the document is parsed.
employee.dtd
<!ELEMENT Employees (employee*)>
<!ELEMENT employee (employeeName, employeeID, dateOfBirth, address)>
<!ELEMENT employeeName (firstName, lastName)>
<!ELEMENT employeeID (#PCDATA)>
<!ELEMENT dateOfBirth (month, date, year)>
<!ELEMENT address (city, state)>
<!ELEMENT firstName (#PCDATA)>
<!ELEMENT lastName (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
employee.xml
<?xml version="1.0"?>
<!DOCTYPE Employees SYSTEM "employee.dtd">
<Employees>
<employee>
<employeeName>
<firstName>Rahul</firstName>
<lastName>Dravid</lastName>
</employeeName>
<employeeID>5012</employeeID>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 16
<dateOfBirth>
<month>January</month>
<date>11</date>
<year>1973</year>
</dateOfBirth>
<address>
<city>Bangalore</city>
<state>Karnataka</state>
</address>
</employee>
</Employees>
DTD Element Rules
There are two basic types of rules that elements must fall into. The first type of rule deals
with content. The second type of rule deals with structure.
 Content Rules: The content rules for .elements deal with the actual data that defined
elements may contain. These rules include the ANY rule, the EMPTY rule, and the
#PCDATA rule.
o The ANY Rule
An element may be defined using the ANY rule. This rule is just what it sounds
like: The element may contain other elements and/or normal character data (just
about anything as long as it is well formed). An element using the ANY rule
would appear as follows:
<!ELEMENT elementname ANY>
o The EMPTY Rule
This rule is the exact opposite of the ANY rule. An element that is defined with
this rule will contain no data. However, an element with the EMPTY rule could
still contain attributes (more on attributes in a bit). The following element is an
example of the EMPTY rule:
<!ELEMENT elementname EMPTY>
o The #PCDATA Rule
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 17
The #PCDATA rule indicates that parsed character data will be contained in the
element. Parsed character data is data that may contain normal markup and will be
interpreted and parsed by any XML parser accessing the document. The following
element demonstrates the #PCDATA rule:
<!ELEMENT elementname (#PCDATA)>
 Structure Rules: The structure rules deal with how that data may be organized. There
are two types of structure rules we will look at here. The first is the “element only” rule.
The second rule is the “mixed” rule.
o The “Element Only” Rule
The “element only” rule specifies that only elements may appear as children of
the current element. The child element sequences should be separated by commas
and listed in the order they should appear. If there are to be options for which
elements will appear, the listed elements should be separated by the pipe symbol.
<!ELEMENT elementname (element1, element2, element3)>
<!ELEMENT elementname (element1 | element2)>
o The “Mixed” Rule
The “mixed” rule is used to help define elements that may have both character
data (#PCDATA) and child elements in the data they contain. A list of options or
a sequential list will be enclosed by parentheses. Options will be separated by the
pipe symbol (|), whereas sequential lists will be separated by commas.
<!ELEMENT elementname (#PCDATA | childelement1 |
childelement2)*>
Element Symbols
Asterisk (*) The data will appear zero or more times (0, 1, 2, …).
<!ELEMENT Employees (employee*)>
Plus sign (+) Signifies that the data must appear one or more times (1, 2, 3, …).
<!ELEMENT Employees (employee+)>
Question mark (?) Data will appear either zero times or one time in the element.
<!ELEMENT Employees (employee?)>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 18
Pipe (|) Separates choices in a set of options.
<!ELEMENT accountType (savings | current | termDeposit)>
DTD Attributes
Attribute list declarations in a DTD will have the following syntax:
<!ATTLIST elementname attributename type defaultbehavior defaultvalue>
 ATTLIST is the tag name that specifies that this definition will be for an attribute list.
 elementname is the name of the element that the attribute will be attached to.
 attributename is the actual name of the attribute.
 type indicates which of the 10 valid kinds of attributes this attribute definition will be.
 defaultbehavior dictates whether the attribute will be required, optional, or fixed in value.
This setting determines how a validating parser should relate to this attribute.
 defaultvalue is the value of the attribute if no value is explicitly set.
<!ATTLIST employeeName
gender CDATA #REQUIRED
country CDATA #IMPLIED >
ATTLIST Declaration
An XML element using the attribute list declared here would appear as follows:
<employeeName gender = “male” country = “India”>
<firstName>Rahul</firstName>
<lastName>Dravid</lastName>
</employeeName>
DTD Entities
Entities in DTDs are storage units. They can also be considered placeholders. Entities are special
markups that contain content for insertion into the XML document. Usually this will be some
type of information that is bulky or repetitive. Entities make this type of information more easily
handled because the DTD author can use them to indicate where the information should be
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 19
inserted in the XML document. This is much better than having to retype the same information
over and over.
The general syntax of an entity is as follows:
<!ENTITY entityname [SYSTEM | PUBLIC] entitycontent>
 ENTITY is the tag name that specifies that this definition will be for an entity.
 entityname is the name by which the entity will be referred in the XML document.
 entitycontent is the actual contents of the entity—the data for which the entity is serving
as a placeholder.
 SYSTEM and PUBLIC are optional keywords. Either one can be added to the definition of
an entity to indicate that the entity refers to external content.
Internal Entity
DTD
<!ENTITY cpy “Copyright RMKCET 2017”>
Usage:
<copyright>&cpy;</copyright>
When the XML document containing the above content is parsed, &cpy; will be replaced with
“Copyright RMKCET 2017” in each instance in which it is used. Using the entity &cpy; saves
the XML document author from having to type in “Copyright RMKCET 2017” over and over.
External Entities
External entities are used to reference external content.
DTD
<!ENTITY rahul SYSTEM “http://srvr/emps/rahul.xml”>
Usage:
<staff>&rahul;</staff>
Non-Text External Entities and Notations
Some external entities will contain non-text data, such as an image file. We do not want the
XML parser to attempt to parse these types of files. The NDATA keyword is used to alert the
parser that the entity content should be sent unparsed to the output document.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 20
A notation is a special declaration that identifies the format of non-text external data so that the
XML application will know how handle the data.
<!NOTATION gif SYSTEM “image/gif” >
<!ENTITY employeephoto SYSTEM “images/employees/rahul.gif” NDATA gif >
<!ELEMENT employee (name, sex, title, years) >
<!ATTLIST employee pic ENTITY #IMPLIED >
…
<employee pic=”employeephoto”>
…
</employee>
Parameter Entities
It is very similar to the internal entity. The main difference between an internal entity and a
parameter entity is that a parameter entity may only be referenced inside the DTD. Parameter
entities can be useful when you have to use a lot of repetitive or lengthy text in a DTD. Use the
following syntax for parameter entities:
<!ENTITY % entityname entitycontent>
The syntax for a parameter entity is almost identical to the syntax for a normal, internal entity.
However, notice that in the syntax, after the declaration, there is a space, a percent sign, and
another space before entityname. This alerts the XML parser that this is a parameter entity and
will be used only in the DTD. These types of entities, when referenced, should begin with % and
end with;.
Drawbacks of DTD
 DTDs are composed of non-XML syntax and are non-extensible.
 There can only be a single DTD per document.
 DTDs are not object oriented. There is no inheritance in DTDs.
 DTDs have weak data typing. DTDs basically have one data type: the text string.
 DTDs does not support namespace very well.
 Number and order of child elements is not properly supported by DTD.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 21
XSD
The W3C XML Schema Definition Language (XSD) is an XML language for describing and
constraining the content of XML documents. W3C XML Schema is a W3C Recommendation.
Built-in Data Types
Some of the XSD Built-in data types:
Namespace URI for XML Schema:
http://www.w3.org/2001/XMLSchema
An element declaration in an XSD schema
<element name="RegisterNumber" type="xsd:integer"/>
The usage of this element in an XML document instance.
<RegisterNumber>12345</ RegisterNumber>
User-Defined Simple Types
A simple element is an XML element that contains only text. It cannot contain any other
elements or attributes. The text can be of many different types. It can be one of the types
XML Schema Type Java Data Type
xsd:string java.lang.String
xsd:integer java.math.BigInteger
xsd:int int
xsd.long long
xsd:short short
xsd:decimal java.math.BigDecimal
xsd:float float
xsd:double double
xsd:boolean boolean
xsd:byte byte
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 22
included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type
that you can define yourself.
One can also add restrictions (facets) to a data type in order to limit its content, or one can
require the data to match a specific pattern.
Example: Defining marks, Range 0-100
<xsd:simpleType name="marks">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
Facets in XSD
 enumeration
 fractionDigits
 length
 maxExclusive
 maxInclusive
 maxLength
 minExclusive
 minInclusive
 minLength
 pattern
Besides <restriction> element, <simpleType> element has <list> and <union> child elements.
The <list> element allows an element or attribute based on the type definition to contain a list of
values of a specified simple data type. The <union> element allows you to combine two or more
simple type definitions to create a collection of values.
User-Defined Complex Types
XSD schema declaration
<complexType name="Student">
<sequence>
<element name="RegisterNumber" type="xsd:integer"/>
<element name="StudentName" type="xsd:string"/>
<element name="DepartmentName" type="xsd:string"/>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 23
<element name="CGPA" type="xsd:decimal"/>
</sequence>
</complexType>
Order Indicators
sequence the elements must appear in the order specified
all the elements must appear, but order is not important
choice specifies that either one child element or another can occur
Occurrence Indicators
maxOccurs specifies the maximum number of times an element can occur
minOccurs specifies the minimum number of times an element can occur
Group Indicators
Group Defines set of related elements
attributeGroup Defines set of related attributes
Table: XSD Indicators
 <xsd:simpleContent> is used when you have an element that can contain structural
markup (complexType) and the element is not allowed to contain child elements. In other
words the elements content type allows only attributes and text content.
<?xml version="1.0" encoding="UTF-8" ?>
<!-- book.xsd -->
<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="bookname" type="xs:string"/>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 24
<xs:element name="isbn" type="xs:string"/>
<xs:element name="authorname">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname"
type="xs:string"/>
<xs:element name="lastname"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="publishername" type="xs:string"/>
<xs:element name="bookprice">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string"
use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 25
<?xml version="1.0"?>
<!-- book.xml -->
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="book.xsd">
<book>
<bookname>Internet and World Wide Web How to Program</bookname>
<isbn>ISBN-10: 0-13-215100-6</isbn>
<authorname>
<firstname>Paul J</firstname>
<lastname>Deitel</lastname>
</authorname>
<publishername>Deitel and Associates, Inc</publishername>
<bookprice currency="rupees">11486</bookprice>
</book>
<book>
<bookname>Java: The Complete Reference</bookname>
<isbn>ISBN-10: 9339212096</isbn>
<authorname>
<firstname>Herbert</firstname>
<lastname>Schildt</lastname>
</authorname>
<publishername>McGraw Hill</publishername>
<bookprice currency="rupees">539</bookprice>
</book>
</books>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 26
XFiles: XPath, XPointer and XLink
XPath
XPath is a syntax for specifying a collection of elements or other information contained within
an XML document.
Conceptually, XPath assumes that the XML document to which XPath expressions will be
applied has been parsed into an internal tree representation. The XPath tree model is similar to
the DOM tree. For example, the nodes in an XPath tree are of different types, such as element,
text, and comment nodes. In addition, unlike the DOM model, the XPath tree model also uses
nodes to represent attribute name value pairs.
The root of the XPath parse tree is known as the document root. Like an instance of Document in
the DOM, this node of the XPath parse tree has a child node representing the root of the element
hierarchy in the parsed document; this node is called the document element.
Location Path
An XPath expression that represents one or more nodes within an XPath parse tree is known as a
location path. A location path can be absolute or relative.
An absolute location path starts with a slash ( / ) and a relative location path does not. In both
cases the location path consists of one or more location steps, each separated by a slash:
An absolute location path:
/step/step/...
A relative location path:
step/step/...
Each step is evaluated against the nodes in the current node-set.A step consists of:
 an axis (defines the tree-relationship between the selected nodes and the current node)
 a node-test (identifies a node within an axis)
 zero or more predicates (to further refine the selected node-set)
The syntax for a location step is:
axisname::nodetest[predicate]
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 27
Table: Some XPath 1.0 Axis Names
Example Result
child::book Selects all book nodes that are children of the current
node
attribute::lang Selects the lang attribute of the current node
child::* Selects all element children of the current node
attribute::* Selects all attributes of the current node
child::text() Selects all text node children of the current node
child::node() Selects all children of the current node
descendant::book Selects all book descendants of the current node
ancestor::book Selects all book ancestors of the current node
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 28
ancestor-or-
self::book
Selects all book ancestors of the current node - and the
current as well if it is a book node
child::*/child::price Selects all price grandchildren of the current node
Table: XPath Axis Name Examples
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 29
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Program: books.xml
Example XPath Expressions
 /bookstore/book/title - selects all the title nodes
 /bookstore/book[1]/title - selects the title of the first book node under the
bookstore element
 /bookstore/book/price[text()] - selects the text from all the price nodes
 /bookstore/book[price>35]/price - selects all the price nodes with a price higher than 35
 /bookstore/book[price>35]/title - selects all the title nodes with a price higher than 35
XPointer
The XML Pointer Language (XPointer) builds on the XPath specification. An XPointer uses
location steps the same as XPath but with two major differences: Because an XPointer describes
a location within an external document, an XPointer can target a point within that XML
document or a range within the target XML document.
Because XPointer builds on the XPath specification, the location steps within an XPointer are
comprised of the same elements that make up XPath location steps.
In addition to the node tests already listed for XPath expressions, XPointer provides two more
important node tests:
 point()
 range()
For this new functionality to work correctly, the XPointer specification added the concept of a
location within an XML document. Within XPointer, a location can be an XPath node, a point, or
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 30
a range. A point can represent the location immediately before or after a specified character or
the location just before or just after a specified node. A range consists of a start point and an end
point and contains all XML information between those two points.
XPointer expressions also allow predicates to be specified as part of a location step in much the
same fashion XPath expressions allow for them.
For an XPath expression, the result from a location step is known as a node set; for an XPointer
expression, the result is known as a location set.
<People>
<Person>
<Name>Dillon Larsen</Name>
<Address>
<Street>123 Jones Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77380</Zip>
</Address>
</Person>
<Person>
<Name>Madi Larsen</Name>
<Address>
<Street>456 Hickory Ln.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77069</Zip>
</Address>
</Person>
<Person>
<Name>John Doe</Name>
<Address>
<Street>214 Papes Way</Street>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 31
<City>Houston</City>
<State>TX</State>
<Zip>77301</Zip>
</Address>
</Person>
</People>
XPointer Expression Location
/People/Person[1]/Name/text()/point()[position()=4] Just after the l and just before the start o
in Dillon
/People/Person[1]/Name/text()/start-
point()[position()=0]
Just before the D in Dillon
/People/Person[2]/Address/ start-point()[position()=2] Just before the <State> element in the
<Person> element for Madi Larsen
/People/Person[2]/Address/ start-point()[position()=0] Just before the <Street> element in
the <Person> element for Madi Larsen
XLink
The XML Linking Language, XLink, allows a link to another document to be specified on any
element within an XML document. The XML Linking Language creates a link to another
resource through the use of attributes specified on elements, not through the actual elements
themselves.
Attribute Description
xlink:type This attribute must be specified and indicates what type of XLink is represented
or defined.
xlink:href This attribute contains the information necessary to locate the desired resource.
xlink:role This attribute describes the function of the link between the current resource and
another.
xlink:arcrole This attributes describes the function of the link between the current resource and
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 1 - CSE/RMKCET 32
another.
xlink:title This attribute describes the meaning of the link between the resources.
xlink:show This attribute indicates how the resource linked to should be displayed.
xlink:actuate This attribute specifies when to load the linked resource.
xlink:label This attribute is used to identify a name for a target resource.
xlink:from This attribute identifies the starting resource.
xlink:to This attribute identifies the ending resource.
Further Reading
1. Validating XML document against XSD.
https://stackoverflow.com/questions/124865/xml-schema-xsd-validation-tool
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 1
S.No. Name of the Topic Reference Book(Text Book)
UNIT II - BUILDING XML- BASED APPLICATIONS
1.
Parsing XML using DOM Chapter 7 (Text 1)
2.
3.
Parsing XML using SAX Chapter 8 (Text 1)
4.
5.
XML Transformation and XSL Chapter 9 (Text 1)
6.
7. XSL Formatting Chapter 9 (Text 1)
8.
Modeling Databases in XML Chapter 10 (Text 1)
9.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 2
XML Processing
XML Parser or Processor is a software module that is used to read XML documents and provide
access to their content and structure.
DOM
The Document Object Model is a platform- and language-neutral standard application
programming interface (API) that will allow programs and scripts to dynamically access and
update the content, structure and style of documents. It is a W3C recommendation.
In DOM-based XML processing, an XML document is first input and parsed, creating a tree
of nodes representing elements, text, comments, and so on. After the tree has been
constructed, methods can be called to modify the tree, extract data from it, and so on.
DOM Levels
The DOM working group works on phases (or levels) of the specification.
 Level 1 allows traversal of an XML document as well as the manipulation of the content
in that document.
 Level 2 extends Level1 with additional features such as namespace support, events,
ranges, and so on.
 Level 3 extends Level 2. It provides features for loading and saving documents and
validation.
DOM Core
The DOM core is available in DOM Level 1 and beyond. It permits you to create and manipulate
XML documents in memory. DOM is a tree structure that represents elements, attributes, and
content.
DOM Interfaces
The DOM interfaces are defined in IDL so that they are language neutral.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 3
Fig: Interface relationships.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 4
Class Description
DocumentBuilder Defines the API to obtain DOM Document instances from an
XML document.
DocumentBuilderFactory Defines a factory API that enables applications to obtain a
parser that produces DOM object trees from XML documents.
JAXP provides a unified approach to creating parser instances through a factory mechanism.
A factory is just an object that is used to create other objects.
<?xml version="1.0"?>
<!DOCTYPE Employees SYSTEM "employee.dtd">
<?xml-stylesheet type="text/xsl" href="employeestyle.xsl" ?>
<Employees>
<employee>
<employeeName>
<firstName>Rahul</firstName>
<lastName>Dravid</lastName>
</employeeName>
<employeeID>5012</employeeID>
<dateOfBirth>
<month>January</month>
<date>11</date>
<year>1973</year>
</dateOfBirth>
<address>
<city>Bangalore</city>
<state>Karnataka</state>
</address>
</employee>
<employee>
<employeeName>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 5
<firstName>Sachin</firstName>
<lastName>Tendulkar</lastName>
</employeeName>
<employeeID>5001</employeeID>
<dateOfBirth>
<month>April</month>
<date>24</date>
<year>1973</year>
</dateOfBirth>
<address>
<city>Mumbai</city>
<state>Maharashtra</state>
</address>
</employee>
</Employees>
Program: employee.xml
package xml;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class DOMDemo {
protected DocumentBuilder documentBuilder;
protected Element root;
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 6
public DOMDemo() throws Exception {
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilder =
documentBuilderFactory.newDocumentBuilder();
}
public static void main(String[] args) throws Exception {
String fileName = "employee.xml";
DOMDemo dom = new DOMDemo();
dom.parse(fileName);
dom.printAllElements();
}
public void parse(String fileName) throws Exception {
File inputFile = new File(fileName);
Document doc = documentBuilder.parse(inputFile);
root = doc.getDocumentElement();
System.out.println("Root element is:" + root.getNodeName());
}
public void printAllElements() throws Exception {
printElement("", root);
}
public void printElement(String indent, Node aNode) {
if (aNode.getNodeType() == Node.TEXT_NODE) {
System.out.println(indent + aNode.getNodeValue());
} else {
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 7
System.out.println(indent + "<" + aNode.getNodeName()
+ ">");
Node child = aNode.getFirstChild();
while (child != null) {
printElement(indent + "t", child);
child = child.getNextSibling();
}
System.out.println(indent + "</" + aNode.getNodeName()
+ ">");
}
}
}
Program: DOMDemo.java
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 8
Creating an XML Document
package xml;
import java.io.File;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
public class DOMCreationDemo {
public static final String xmlFilePath = "company.xml";
public static void main(String argv[]) {
try {
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 9
DocumentBuilderFactory documentFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder =
documentFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
// root element
Element root = document.createElement("company");
document.appendChild(root);
// employee element
Element employee = document.createElement("employee");
root.appendChild(employee);
// set an attribute to staff element
Attr attr = document.createAttribute("id");
attr.setValue("10");
employee.setAttributeNode(attr);
// firstname element
Element firstName = document.createElement("firstname");
firstName.appendChild(document.createTextNode("Sachin"));
employee.appendChild(firstName);
// lastname element
Element lastname = document.createElement("lastname");
lastname.appendChild(document.createTextNode("Tendulkar"));
employee.appendChild(lastname);
// email element
Element email = document.createElement("email");
email.appendChild(document.createTextNode("sachin.tendulkar@gmail
.com"));
employee.appendChild(email);
// department elements
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 10
Element department = document.createElement("department");
department.appendChild(document.createTextNode("Batting"));
employee.appendChild(department);
// create the xml file
// transform the DOM Object to an XML File
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
DOMSource domSource = new DOMSource(document);
StreamResult streamResult = new StreamResult(new
File(xmlFilePath));
transformer.transform(domSource, streamResult);
System.out.println("Done creating XML File");
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
}
}
DOM Traversal and Range
Traversal and range are features added in DOM Level 2.You can determine whether traversal is
supported by calling the hasFeature()method of the DOMImplementation interface. For
traversal, you can use the arguments“Traversal” and “2.0” for the feature and version parameters
of the hasFeature()method.
Traversal
Traversal is a convenient way to walk through a DOM tree and select specific nodes.This is
useful when you want to find certain elements and perform operations on them.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 11
Interface Description
NodeIterator Used to walk through nodes linearly. Represents a subtreeas a linear list.
TreeWalker Represents a subtree as a tree view.
NodeFilter Can be used in conjunction with NodeIterator andTreeWalker to select
specific nodes.
DocumentTraversal Contains methods to create NodeIterator andTreeWalker instances.
Table: Summary of Traversal Interfaces
Range
Range interfaces provide a convenient way to select, delete, extract, and insert content. You can
determine whether range is supported by calling the hasFeature(...) method of the
DOMImplementation interface. You can use the arguments “Range” and “2.0” for feature and
version. There are a number of applications for which the range interfaces are useful.
A range consists of two boundary points corresponding to the start and the end of the range. A
boundary point’s position in a Document or DocumentFragment tree can be characterized by a
node and an offset. The node is the container of the boundary point and its position. The
container and its ancestors are the ancestor containers of the boundary point and its position. The
offset within the node is the offset of the boundary point and its position. If the container is an
Attr, Document, DocumentFragment, Element, or EntityReference node, the offset is between its
child nodes. If the container is a CharacterData, Comment, or ProcessingInstruction node, the
offset is between the16-bit units of the UTF-16 encoded string contained by it.
Interface Description
Range This interface describes a range and contains methods to define, delete,
insert content.
DocumentRange This interface creates a range.
Table: Summary of Range Interfaces
DOM Implementations
The DOM working group supplies Java language bindings as part of the DOM specification. The
specification and Java language bindings are available at the W3C Web site. These bindings are
sets of Java source files containing Java interfaces, and they map exactly to the DOM interfaces.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 12
The package org.w3c.dom contains the Java interfaces but does not include a usable
implementation. In order to make the interfaces do something useful, you will need an
implementation, or a parser. A number of DOM implementations are available for Java.
Java APIs for XML Processing (JAXP)
The Java API for XML Processing or JAXP is one of the Java XML Application
programming interfaces (API). It provides the capability of validating and parsing XML
documents. javax.xml.parsers: The JAXP APIs, which provide a common interface for
different vendors' SAX and DOM parsers.
Xerces
JDOM
Small DOM-like Implementations
Meant for smaller devices.
 NanoXML
 TinyXML
 kXML
SAX – Event Oriented Parsing
 SAX (Simple API for XML) is an API that can be used to parse XML documents.
 SAX provides a framework for defining event listeners, or handlers. These handlers are
written by developers interested in parsing documents with a known structure. The handlers
are registered with the SAX framework in order to receive events. Events can include start of
document, start of element, end of element, and so on. The handlers contain a number of
methods that will be called in response to these events. Once the handlers are defined and
registered, an input source can be specified and parsing can begin.
Class Description
SAXParser Defines the API that wraps an XMLReader implementation class.
SAXParserFactory Defines a factory API that enables applications to configure and
obtain a SAX based parser to parse XML documents.
Table: javax.xml.parsers
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 13
The basic steps to perform SAX Parsing to an XML Document are:
 Create an new instance of SAXParserFactory
 Use the appropriate handlers to hand the events of the parsing process by extending the
DefaultHandler class
 Create the appropriate callback functions to handle the events, e.g. when a new element is
found
package xml;
import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXDemo extends DefaultHandler {
public void startDocument() {
System.out.println("***Start of Document***");
}
public void endDocument() {
System.out.println("***End of Document***");
}
public void startElement(String uri, String localName, String
qName, Attributes attributes) {
System.out.print("<" + qName);
int n = attributes.getLength();
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 14
for (int i = 0; i < n; i += 1) {
System.out.print("" + attributes.getQName(i) + "='" +
attributes.getValue(i) + "");
}
System.out.println(">");
}
public void characters(char[] ch, int start, int length) {
System.out.println(new String(ch, start, length).trim());
}
public void endElement(String namespaceURI, String localName,
String qName) throws SAXException {
System.out.println("</" + qName + ">");
}
public static void main(String args[]) throws Exception {
String fileName = "employee.xml";
SAXDemo handler = new SAXDemo();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(new File(fileName), handler);
}
}
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 15
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 16
ErrorHandler contains three methods that can be used to determine whether a document
iswell formed and valid.Either error() or warning() will be called if the document is well formed
but not valid(that is, it violates the rules of the DTD), and fatalError() will be called if the
documentis not well formed.
/*SAX Validation*/
package xml;
import java.io.FileReader;
import org.xml.sax.InputSource;
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 17
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
public class SAXValidationDemo extends DefaultHandler {
private boolean valid;
private boolean wellFormed;
public SAXValidationDemo() {
valid = true;
wellFormed = true;
}
public void startDocument() {
System.out.println("***Start of Document***");
}
public void endDocument() {
System.out.println("***End of Document***");
}
public void error(SAXParseException e) {
valid = false;
}
public void fatalError(SAXParseException e) {
wellFormed = false;
}
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 18
public void warning(SAXParseException e) {
valid = false;
}
public boolean isValid() {
return valid;
}
public boolean isWellFormed() {
return wellFormed;
}
public static void main(String args[]) throws Exception {
XMLReader parser = XMLReaderFactory.createXMLReader();
SAXValidationDemo handler = new SAXValidationDemo();
parser.setContentHandler(handler);
parser.setErrorHandler(handler);
parser.parse(new InputSource(new
FileReader("employee.xml")));
if (!handler.isWellFormed()) {
System.out.println("Document is NOT well formed.");
}
if (!handler.isValid()) {
System.out.println("Document is NOT valid.");
}
if (handler.isWellFormed() && handler.isValid()) {
System.out.println("Document is well formed and
valid.");
}
}
}
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 19
Lexical Events
LexicalHandler interface, part of org.xml.sax.ext package, is used to capture events like
comments, CDATA and DTD references.
Comparing DOM and SAX
S.No. DOM SAX
1 Tree Based: The DOM parser first read
and parse anentire XML document into a
tree representation and then process this
tree.
Event Based: The SAX parser interact
with an application as itreads an XML
document. As an XML parser is reading
an XML document, certainevents occur.
2 More CPU time& Memory:Theentire
document tree must be created, even if
only a fraction of the document is
actuallyrelevant to the software
processing the document. Hence
consumes more CPU power and
memory.
Less CPU time & Memory: Only the
relevant element is parsed at a time. It
consumes less CPU power and memory
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 20
JAXB
Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML
schemas and Java representations, making it easy for Java developers to incorporate XML data
and processing functions in Java applications. As part of this process, JAXB provides methods
for unmarshalling (reading) XML instance documents into Java content trees, and then
marshalling (writing) Java content trees back into XML instance documents. JAXB also provides
a way to generate XML schema from Java objects.
The general steps in the JAXB data binding process are:
1. Generate classes: An XML schema is used as input to the JAXB binding compiler to
generate JAXB classes based on that schema.
xjc: JAXB tool that compiles an XML schema file into fully annotated Java classes
Customizing in JAXB2.0
xjc -b <file> <schema>
Eg: xjc schema1.xsd schema2.xsd schema3.xsd -b bindings123.xjb
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 21
2. Compile classes: All of the generated classes, source files, and application code must be
compiled.
3. Unmarshal: XML documents written according to the constraints in the source schema
are unmarshalled by the JAXB binding framework. Note that JAXB also supports
unmarshalling XML data from sources other than files/documents, such as DOM nodes,
string buffers, SAX Sources, and so forth.
4. Generate content tree: The unmarshalling process generates a content tree of data
objects instantiated from the generated JAXB classes; this content tree represents the
structure and content of the source XML documents.
5. Validate (optional): The unmarshalling process optionally involves validation of the
source XML documents before generating the content tree. Note that if you modify the
content tree in Step 6, below, you can also use the JAXB Validate operation to validate
the changes before marshalling the content back to an XML document.
6. Process content: The client application can modify the XML data represented by the
Java content tree by means of interfaces generated by the binding compiler.
7. Marshal: The processed content tree is marshalled out to one or more XML output
documents. The content may be validated before marshalling.
8.
Comparing with DOM and SAX
 DOM: JAXB is faster and requires less memory when compared with DOM.
 SAX: There is no need to create and use a parser and no need to write a content handler
with callback methods. What this means is that developers can access and process XML
data without having to know XML or XML processing.
<!--address.xml-->
<address>
<name>Ajeeth</name>
<company>Google</company>
<phone>(011) 123-4567</phone>
</address>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 22
/*POJO mapped to XML using set of JAXB annotations*/
package xml;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "address")
public class Address {
private String name;
private String company;
private String phone;
public String getName() {
return name;
}
@XmlElement(name = "name")
public void setName(String name) {
this.name = name;
}
public String getCompany() {
return company;
}
@XmlElement(name = "company")
public void setCompany(String company) {
this.company = company;
}
public String getPhone() {
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 23
return phone;
}
@XmlElement(name = "phone")
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Address [name=" + name + ", company=" + company + ",
phone=" + phone + "]";
}
}
/*Unmarshaling – XML to Java*/
package xml;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class JAXBUnmarshalDemo {
public static void main(String[] args) {
try {
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 24
File file = new File("address.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Address.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Address address = (Address) jaxbUnmarshaller.unmarshal(file);
System.out.println(address);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
Output
Address [name=Ajeeth, company=Google, phone=(011) 123-4567]
/*Marshaling – Java Objects to XML*/
package xml;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class JAXBMarshalDemo {
public static void main(String[] args) {
Address address = new Address();
address.setName("Rahul Dravid");
address.setCompany("Rajasthan Royals");
address.setPhone("99999 88888");
try {
File file = new File("address.xml");
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 25
JAXBContext jaxbContext = JAXBContext.newInstance(Address.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
//File Output
jaxbMarshaller.marshal(address, file);
//Console Output
jaxbMarshaller.marshal(address, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
Output
S.No. Methods Description
1 public abstract Marshaller
createMarshaller() throws
Create a Marshaller object that can be used to convert a
java content tree into XML data.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 26
JAXBException
2 public abstract Unmarshaller
createUnmarshaller() throws
JAXBException
Create an Unmarshaller object that can be used to convert
XML data into a java content tree.
3 public static void
marshal(Object jaxbObject,
File xml)
Writes a Java object tree to XML and store it to the
specified location.
4 public static JAXBContext
newInstance(Class...
classesToBeBound)
throws JAXBException
Obtain a new instance of a JAXBContext class.
Annotation Type Description
@XmlRootElement(name=”Student”) Maps a class or an enum type to an XML element.
@XmlElement(name=”regno”) Maps a JavaBean property to a XML element derived
from property name.
@XmlAttribute Maps a JavaBean property to a XML attribute.
XSL
XSL is a family of recommendations for defining XML document transformation and
presentation. It consists of three parts:
 XSL Transformations (XSLT): It is a language for transforming XML.
 The XML Path Language (XPath): It is an expression language used by XSLT (and
many other languages) to access or refer to parts of an XML document.
 XSL Formatting Objects (XSL-FO): It is an XML vocabulary for specifying formatting
semantics.
ExtensibleStylesheet Language (XSL) is a “programming language” that allows extraction of
information from oneXMLtext documentand uses that information to create another XML text
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 27
document.XSL is an XML vocabulary; that is, XSL documents arewell-formed XML documents.
So the transformation “program” is an XML document.
AnXSL document normally contains two types of information: template data, which is textthat is
copied to the output XML text document with little or no change; and XSL markup,which
controls the transformation process.
XSLT: Template-based Transformation
 First, the root element of an XSLT document can be named either transform or stylesheet.
There is no semantic difference between these elements.
 The content of the root element often consists of one or more template elements. Each
template represents a template rule, which typically consists of two parts:
o An XPath expression specified as the value of the template element’s match attribute
and known as the template rule’s pattern.
o The content of the template rule, which is known as the template portion of the rule.
 Software for performing an XSLT transformation, such as JAXP, is known as an XSLT
processor. An XSLT processor is given two inputs—an XSLT document and asource XML
document—and produces a single result XML document. Internally, an XSLTprocessor
represents each of these documents as an XPath tree, called the source tree, thestyle-sheet
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 28
tree, and the result tree, respectively. Since all three trees are XPath trees, nodes in any of
these trees can be referenced using XPathexpressions.
<?xml version="1.0" encoding="utf-8" ?>
<!-- student.xml -->
<?xml-stylesheet type="text/xsl" href="studentstyle.xsl" ?>
<students>
<student>
<registernumber>1001</registernumber>
<name>Badrinath</name>
<cgpa>8.1</cgpa>
</student>
<student>
<registernumber>1002</registernumber>
<name>Dhoni</name>
<cgpa>6.5</cgpa>
</student>
<student>
<registernumber>1003</registernumber>
<name>Rahul</name>
<cgpa>9.6</cgpa>
</student>
<student>
<registernumber>1004</registernumber>
<name>Sachin</name>
<cgpa>8.8</cgpa>
</student>
<student>
<registernumber>1005</registernumber>
<name>Sehwag</name>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 29
<cgpa>8.9</cgpa>
</student>
<student>
<registernumber>1006</registernumber>
<name>Yuvraj</name>
<cgpa>9.1</cgpa>
</student>
</students>
Program: XML document (Source Tree)
<?xml version="1.0" encoding="utf-8" ?>
<!-- studentstyle.xsl -->
<xsl:stylesheetversion="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="students">
<html><head><title>Style Sheet for student.xml</title></head><body>
<table border="1" align="center">
<tr style="background-color:khaki;color:blue;">
<th>REGISTER NUMBER</th>
<th>NAME</th>
<th>CGPA</th>
</tr>
<xsl:for-each select="student">
<xsl:sort select="cgpa" data-type="number" order="descending" />
<tr>
<td><xsl:value-of select="registernumber" /></td>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="cgpa" /></td>
</tr>
</xsl:for-each>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 30
</table>
</body></html>
</xsl:template>
</xsl:stylesheet>
Program: XSL transformation to represent XML document as HTML Table
<xsl: template> Contains rule to apply when a specified node is
matched.
<xsl: value-of select=”expression”> Selects the value of an XML document and adds it to
the output tree of the transformation. The required
select attribute contains an XPath expression.
<xsl: for-each select=”expression”> Applies a template to every node selected by the
XPath specified by the select attribute.
<xsl: sort select=”expression”> Used as a child element of an <xsl:apply-templates>
or <xsl: for-each> element. Sorts the nodes selected
by the <xsl: apply-template> or <xsl: for-each>
element so that the nodes are processed in sorted
order.
<xsl: apply templates> Applies the templates of the XSL document to the
children of the current node.
<xsl: apply-templates
match=”expression”>
Applies the templates of the XSL document to the
children of expression. The value of the attribute
match(i.e., expression) must be an XPath expression
that specifies elements.
<xsl:iftest = “boolean-expression”> Used to perform conditional statements against the
contents of the XML document.
Table: XSL Elements
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 31
XSL for Business-to-Business (B2B) Communication
XSLT can also be used in for B2B communication—the process of exchanging data between two
different companies. Developers can leverage XML to describe the data in a vendor-independent
fashion. In the ideal case, both companies will agree upon a standard vocabulary for describing
the data using a DTD or schema. The vocabulary is composed of the XML element names used
in the XML document. However, in certain cases one of the companies might like to use a
different vocabulary. This is where XSL enters the picture.
The example in this section describes a B2B scenario between a training company, Hot Shot
Training, and a software development company, AcmeSoft. The computer training company
maintains a database for the students that have attended its courses. The training company has
developed an XML application that produces the list of students for a given class.
The management team at AcmeSoft would like to retrieve this list from the training company’s
XML application. However, once the data is retrieved, AcmeSoft would like to store the data in a
different XML format using its own XML element names.
The XML application at the training company is accessible using the HTTP protocol. The first
step is to request the XML document from the training company. In step 2, the XML document
is retrieved. In step 3, the document is transformed using the supplied XSLT style sheet. Finally,
the desired output document is produced in step 4.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 32
<?xml version=”1.0”?>
<trainingclass>
<title>J2EE Essentials</title>
<start_date>24 Sep 2001</start_date>
<end_date>28 Sep 2001</end_date>
<location>Philadelphia, PA</location>
<student>
<first_name>Riley</first_name>
<last_name>Scott</last_name>
<email>riley@acmesoft.web</email>
</student>
<student>
<first_name>Torrance</first_name>
<last_name>Lee</last_name>
<email>torrance.lee@acmesoft.web</email>
</student>
</trainingclass>
Program: XML document used in Hot Shot Training Company
<?xml version=”1.0”?>
<employeelist>
<course_title>J2EE Essentials</course_title>
<course_date start=”24 Sep 2001” end=”28 Sep 2001” />
<location>Philadelphia, PA</location>
<employee>
<name>
<first>Riley</first>
<last>Scott</last>
</name>
<email>riley.scott@acmesoft.web</email>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 33
</employee>
<employee>
<name>
<first>Torrance</first>
<last>Lee</last>
</name>
<email>torrance.lee@acmesoft.web</email>
</employee>
</employeelist>
Program: XML document used in AcmeSoft
<?xml version=”1.0”?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”
version=”1.0”>
<xsl:template match=”/trainingclass”>
<employeelist>
<course_title><xsl:value-of select=”title” /></course_title>
<!-- create attributes for the start and end course dates -->
<course_date>
<xsl:attribute name=”start”>
<xsl:value-of select=”start_date”/>
</xsl:attribute>
<xsl:attribute name=”end”>
<xsl:value-of select=”end_date”/>
</xsl:attribute>
</course_date>
<location><xsl:value-of select=”location” /></location>
<!-- Perform a loop for each student in the training class -->
<xsl:for-each select=”student”
<employee>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 34
<name>
<first><xsl:value-of select=”first_name”/></first>
<last><xsl:value-of select=”last_name”/></last>
</name>
<email><xsl:value-of select=”email”/></email>
</employee>
</xsl:for-each>
</employeelist>
</xsl:template>
</xsl:stylesheet>
Program: Stylesheet to transform XML document used in Hot Spot to XML document
used in AcmeSoft
XSL-FO
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 35
 XSL-FO elements use the following namespace:
http://www.w3.org/1999/XSL/Format
 The element <fo:root> is the root element for the XSL-FO document.
 An XSL-FO document is divided into two main parts:
1. One layout master set (layout-master-set), which specifies one or more page master
templates (simple-page-master) to be used in the document.
2. One or more page sequences, which contain the content of the document.
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="hello"
page-height="11in" page-width="8.5in" margin-top="1in"
margin-bottom="1in" margin-left="1in" margin-right="1in">
<fo:region-body margin-top="1in" margin-bottom=".5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="hello">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="18pt" text-align="center" font-weight="bold">
Hello World!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 36
Fig: Pagination Tree Structure
Page Master Set: <fo:layout-master-set>
A document can be composed of multiple pages, each with its own dimensions. The pagemaster
set refers to the collection of page masters.
Page Master: <fo:simple-page-master>
The page master describes the page size and layout. For example, we could use an8.5×11-inch
page or an A4 letter. The page master contains the dimensions for a page, including width,
height, and margins.
Regions
The simple-page-master FO contains region settings in the form of the following child FOs.
 <fo:region-before>
 <fo:region-after>
 <fo:region-body>
 <fo:region-start>
 <fo:region-end>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 37
The region-before and region-after areas are commonly used for page headers andfooters. The
region-body area is the center of the page and contains the main content.The region-start and
region-end sections are commonly used for left and right sidebars,respectively.
Page Sequences: <fo:page-sequence>
 A page sequence defines a series of printed pages. Each page sequence refers to a page
master for its dimensions. The page sequence contains the actual content for the document.
 The <fo:page-sequence> element contains <fo:static-content> and <fo:flow>
elements.
 The <fo:static-content> element is used for page headers and footers. For example, we
can define a header for the company name and page number, and this information will appear
on every page.
 The <fo:flow>element contains a collection of text blocks. The <fo:flow> element is
similar to a collection of paragraphs. A body of text is defined using the <fo:block>
element.
 The <fo:block> element is a child element of <fo:flow>. The <fo:block> element
contains free-flowing text that will wrap to the next line in a document if it overflows.
Page Headers and Footers
The header is defined using the following code fragment:
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 38
<!-- header -->
<fo:static-content flow-name=”xsl-region-before”>
<fo:block text-align=”end”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Ez Books Catalog - page <fo:page-number/>
</fo:block>
</fo:static-content>
The footer is defined using the following code fragment:
<!-- footer -->
<fo:static-content flow-name=”xsl-region-after”>
<fo:block text-align=”center”
font-size=”10pt”
font-family=”serif”
line-height=”14pt” >
Visit our website http://www.ezbooks.web
</fo:block>
</fo:static-content>
Graphics
XSL-FO also allows for the insertion of external graphic images. The graphic formatssupported
are dependent on the XSL-FO formatting engine. The Apache-FOP formatting engine supports
the popular graphics formats: GIF, JPEG, and BMP.
The following code fragment inserts the image smiley.jpg:
<fo:block text-align=”center”>
<fo:external-graphic src=”smiley.jpg” width=”200px” height=”200px”/>
</fo:block>
Tables
XSL-FO has rich support for structuring tabular data.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 39
<fo:table>
<!-- define column widths -->
<fo:table-column column-width=”120pt”/>
<fo:table-column column-width=”200pt”/>
<fo:table-column column-width=”80pt”/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight=”bold”>Author</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Title</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-weight=”bold”>Price (USD)</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<!-- insert table body and rows here -->
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>Michael Daconta</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>XML Development with Java 2</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>37.99</fo:block>
</fo:table-cell>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 40
</fo:table-row>
</fo:table-body>
</fo:table>
Modeling Databases in XML
Need for Integrating XML and Database
With the emergence of XML as a technique for describing data, the frequently asked question is,
“How can we integrate XML with our existing relational database?” In particular, developers
need a solution to dynamically generate XML documents using information stored in databases.
XML and database integration is important because XML provides a standard technique to
describe data. By leveraging XML, a company can convert its existing corporate data into a
format that is consumable by its trading partners. XML allows the development team to define a
set of custom tags specific to its industry. A trading partner can import the XML data into its
system using the given format. The trading partner also has the option of converting the data to a
different XML format using XSLT.
XML Database Solutions
XML Database Mapping
The first type of XML database solution provides a mapping between the XML document
and the database fields. The system dynamically converts SQL result sets to XML
documents.
Fig: Mapping XML documents to database fields.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 41
Native XML Support (Native XML database or NXD)
The second type of XML database solution actually stores the XML data in the document
in its native format. Each product uses its own proprietary serialization technique to store
the data. However, when the data is retrieved, it represents an XML document.
Fig: Native XML databases.
JAXB Solution for Modeling Databases in XML
1. Review the database schema.
2. Construct the desired XML document.
3. Define a schema for the XML document.
4. Create the JAXB binding schema.
5. Generate the JAXB classes based on the schema.
6. Develop a Data Access Object (DAO).
7. Develop a servlet for HTTP access.
Fig: The rental property application architecture.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 42
Step 1: Review the database schema
Step 2: Construct the desired XML document
<rental_property>
<prop_id>1</prop_id>
<name>The Meadows</name>
<address>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 43
<street>251 Eisenhower Blvd</street>
<city>Houston</city>
<state>TX</state>
<postal_code>77033</postal_code>
</address>
<square_footage>500.0</square_footage>
<bedrooms>1.0</bedrooms>
<bath>1.0</bath>
<price>600</price>
<contact>
<phone>555-555-1212</phone>
<fax>555-555-1414</fax>
</contact>
</rental_property>
Step 3: Define a schema for the XML document
<!ELEMENT rental_property_list (rental_property)*>
<!ELEMENT rental_property (prop_id, name, address, square_footage,
bedrooms, bath, price, contact)>
<!ELEMENT prop_id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (street, city, state, postal_code)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT postal_code (#PCDATA)>
<!ELEMENT square_footage (#PCDATA)>
<!ELEMENT bedrooms (#PCDATA)>
<!ELEMENT bath (#PCDATA)>
<!ELEMENT price (#PCDATA)>
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 44
<!ELEMENT contact (phone, fax)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT fax (#PCDATA)>
Step 4: Create the JAXB binding schema
JAXB 1.0 binding schema files normally use the filename extension .xjs (for XML Java schema).
But JAXB 2.0 uses .xjb. JAXB uses a default binding schema that will create properties in the
Java class based on the XML element name. But we can customize the default binding schema as
follows:
Fig: Example JAXB 1.0 Customized Binding Schema (.xjs)
<jxb:bindings schemaLocation = "xs:anyURI">
<jxb:bindings node = "xs:string">*
<binding declaration>
<jxb:bindings>
</jxb:bindings>
Fig: JAXB 2.0 Customized Binding Schema (.xjb) General Form
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 45
Step 5: Generate the JAXB classes based on the schema
Using JAXB binding compiler, Java classes are generated from XSD/DTD (One or many bean
classes and ObjectFactory class).
Fig: Generating Java classes with the JAXB compiler
Using JAXB1.0
java com.sun.tools.xjc.Main rental_property.dtd rental_property.xjs -d
source_code
This command generates source code in the source_code directory. The following files are
generated:
 RentalPropertyList.java. This file models the <rental_property_list> element.
 RentalProperty.java. This file models the <rental_property> element.
 Address.java. This file models the <address> subelement.
 Contact.java. This file models the <contact> subelement.
Step 6: Develop a Data Access Object (DAO)
A Data Access Object (DAO) provides access to the backend database. The goal of the DAO
design pattern is to provide a higher level of abstraction for database access. The DAO
encapsulates the complex JDBC and SQL calls. The DAO provides access to the backend
database via public methods. The DAO converts a result set to a collection of objects. The
objects model the data stored in the database.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 2 - CSE/RMKCET 46
Fig: Data Access Object design pattern
Step 7: Develop a servlet for HTTP access
Fig: Servlet and DAO interaction
In our solution, we’ll use a servlet to handle the requests to the DAO. In the servlet, we’ll call the
appropriate method and return the result as an XML document.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 1
S.No. Name of the Topic Reference Book (Text Book)
UNIT III - SERVICE ORIENTED ARCHITECTURE
1.
Characteristics of SOA Thomas Erl – Ch: 3.2
2.
3. Comparing SOA with Client-Server Thomas Erl – Ch: 4.3
4.
Comparing SOA with Distributed
architectures
Thomas Erl – Ch: 4.3
5. Benefits of SOA Thomas Erl – Ch: 3.4
6.
Principles of Service orientation Thomas Erl – Ch: 8.3
7.
8.
Service layers Thomas Erl – Ch: 9.0
9.
Contents beyond syllabus CORBA, RMI, IIOP
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 2
Need for SOA
The Challenges faced by Enterprise Computing before the advent of Service Oriented
Architecture (SOA) were:
 Scalability
 Heterogeneity
 Time-to-market
 Cost
o Development
o Operation & Maintenance
The issues of Scalability and Heterogeneity were addressed by Component Based Technologies
(eg: J2EE – Open, standards based Component & Container model). But the remaining issues of
Time-to-market and Cost were not adequately addressed by Component Based Technologies.
SOA addresses all of the above mentioned issues.
Service Oriented Architecture
“Service-oriented architecture” is a term that represents a model in which automation logic is
decomposed into smaller, distinct units of logic known as services. This model should adhere to
the principles of service-orientation like loose coupling, autonomy, reusability, composability,
statelessness, discoverability, abstraction etc.
Service
It is a unit of processing logic. Collectively, these units comprise a larger piece of business
automation logic. Individually, these units can be distributed.
Primitive SOA
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 3
It is baseline technology architecture, whose core components are services, descriptions, and
messages. It supports the basic service oriented principles.
What is architecture?
 A baseline application that could act as a template for all other applications.
 It specifically explains the technology, boundaries, rules, limitations, and design
characteristics that apply to all solutions based on this template.
Application Architecture
 It is a technical blueprint for providing solutions.
 An organization can have several application architectures.
Enterprise Architecture
 It is a master specification providing high-level overview of all forms of heterogeneity
that exist within an enterprise. It also contains definition of the supporting architecture.
 Any changes to enterprise architecture directly affect application architectures.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 4
Characteristics of SOA
Contemporary SOA
It extends primitive SOA through application of advanced design techniques and new Web
services specifications.
Contemporary SOA represents an open, agile, extensible, federated, composable architecture
comprised of autonomous, QoS-capable, vendor diverse, interoperable, discoverable, and
potentially reusable services, implemented as Web services.
Observational Characteristics
 Contemporary SOA is at the core of the service-oriented computing platform
The term “architecture” refers to any application computing platform. Contemporary
SOA represents an architecture that promotes service-orientation through the use of web
services.
 Contemporary SOA is a building block
Organizations standardizing on SOA work toward an ideal known as the service-oriented
enterprise (SOE), where all business processes are composed of and exist as services,
both logically and physically. In this scenario an individual service-oriented application
can, in its entirety, be represented by and modeled as a single service.
 Contemporary SOA is an evolution
It differs from traditional client-server and distributed environments in that it is heavily
influenced by the concepts and principles associated with service-orientation and Web
services. It is similar to previous platforms in that it preserves the successful
characteristics of its predecessors and builds upon them with distinct design patterns and
a new technology set. For example, SOA supports and promotes reuse, as well as the
componentization and distribution of application logic.
 Contemporary SOA is still maturing
Despite the fact that Web services are being used to implement a great deal of application
functionality, the support for a number of features necessary for enterprise-level
computing is not yet fully available.
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 5
When SOA platforms and tools reach an adequate level of maturity, the utilization of
Web services can be extended to support the creation of enterprise SOA solutions.
 Contemporary SOA is an achievable ideal
A standardized enterprise-wide adoption of SOA requires an enormous amount of effort,
discipline, and a good amount of time. It is a transition phase now, where various parts of
SOA will be phased in at different stages and to varying extents. This will likely result in
countless hybrid architectures, consisting mostly of distributed environments that are part
legacy and part service-oriented. The advancements in technology set will help in
realizing enterprise-level SOAs.
Concrete Characteristics
 Contemporary SOA increases quality of service
Common quality of service requirements:
Security: Protecting the contents of a message, as well as access to individual services.
Reliability: Guaranteeing message delivery or notification of failed delivery.
Performance: Ensuring that the overhead imposed by SOAP message and XML content
processing does not inhibit the execution of a task.
Transaction: Protecting the integrity of specific business tasks with a guarantee that
should the task fail, exception logic is executed.
WS-* Extensions provide features that directly address the quality of
service requirements.
 Contemporary SOA is fundamentally autonomous
Services are autonomous. Messages are autonomous. SOA builds upon and expands this
principle by promoting the concept of autonomy throughout solution environments and
the enterprise.
 Contemporary SOA is based on open standards
Data exchange is governed by open standards. The message itself is standardized, both in
format and in how it represents its payload. The use of SOAP, WSDL, XML, and XML
Schema allow for messages to be fully self-contained and support the underlying
agreement that to communicate, services require nothing more than knowledge of each
other's service descriptions. The use of an open, standardized messaging model
IT6801 SERVICE ORIENTED ARCHITECTURE
UNIT 3 - CSE/RMKCET 6
eliminates the need for underlying service logic to share type systems and supports the
loosely coupled paradigm.
An SOA limits the role of proprietary technology to the implementation and hosting of
the application logic encapsulated by a service.
 Contemporary SOA supports vendor diversity
Disparate technology platforms do not prevent service-oriented solutions from
interoperating.
 Contemporary SOA fosters intrinsic interoperability
Intrinsically interoperable services enable unforeseen integration opportunities.
Promoting this characteristic can significantly alleviate the cost and effort of fulfilling
future cross-application integration requirements.
 Contemporary SOA promotes discovery
SOA supports and encourages the advertisement and discovery of services throughout the
enterprise and beyond. A serious SOA will likely rely on some form of service registry or
directory to manage service descriptions. UDDI is the Web services registry standard.
 Contemporary SOA promotes federation
While Web services enable federation, SOA promotes this cause by establishing and
standardizing the ability to encapsulate legacy and non-legacy application logic and by
exposing it via a common, open, and standardized communications framework.
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture

Mais conteúdo relacionado

Mais procurados

Cloud Security, Standards and Applications
Cloud Security, Standards and ApplicationsCloud Security, Standards and Applications
Cloud Security, Standards and ApplicationsDr. Sunil Kr. Pandey
 
Pgp pretty good privacy
Pgp pretty good privacyPgp pretty good privacy
Pgp pretty good privacyPawan Arya
 
Key management and distribution
Key management and distributionKey management and distribution
Key management and distributionRiya Choudhary
 
Chapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsChapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsAbDul ThaYyal
 
Implementation levels of virtualization
Implementation levels of virtualizationImplementation levels of virtualization
Implementation levels of virtualizationGokulnath S
 
secure file storage on cloud using hybrid Cryptography ppt.pptx
secure file storage on cloud using hybrid Cryptography  ppt.pptxsecure file storage on cloud using hybrid Cryptography  ppt.pptx
secure file storage on cloud using hybrid Cryptography ppt.pptxNishmithaHc
 
Message passing ( in computer science)
Message   passing  ( in   computer  science)Message   passing  ( in   computer  science)
Message passing ( in computer science)Computer_ at_home
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanismsRajapriya82
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systemssumitjain2013
 
Open Cloud Consortium Overview (01-10-10 V6)
Open Cloud Consortium Overview (01-10-10 V6)Open Cloud Consortium Overview (01-10-10 V6)
Open Cloud Consortium Overview (01-10-10 V6)Robert Grossman
 
Topic1 substitution transposition-techniques
Topic1 substitution transposition-techniquesTopic1 substitution transposition-techniques
Topic1 substitution transposition-techniquesMdFazleRabbi18
 

Mais procurados (20)

Cloud Security, Standards and Applications
Cloud Security, Standards and ApplicationsCloud Security, Standards and Applications
Cloud Security, Standards and Applications
 
Pgp pretty good privacy
Pgp pretty good privacyPgp pretty good privacy
Pgp pretty good privacy
 
Key management and distribution
Key management and distributionKey management and distribution
Key management and distribution
 
CLOUD COMPUTING AND STORAGE
CLOUD COMPUTING AND STORAGECLOUD COMPUTING AND STORAGE
CLOUD COMPUTING AND STORAGE
 
Chapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systemsChapter 1 characterisation of distributed systems
Chapter 1 characterisation of distributed systems
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Implementation levels of virtualization
Implementation levels of virtualizationImplementation levels of virtualization
Implementation levels of virtualization
 
SLA Management in Cloud
SLA Management in CloudSLA Management in Cloud
SLA Management in Cloud
 
Comet Cloud
Comet CloudComet Cloud
Comet Cloud
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
secure file storage on cloud using hybrid Cryptography ppt.pptx
secure file storage on cloud using hybrid Cryptography  ppt.pptxsecure file storage on cloud using hybrid Cryptography  ppt.pptx
secure file storage on cloud using hybrid Cryptography ppt.pptx
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
SOA unit-3-notes-Introduction to Service Oriented Architecture
SOA unit-3-notes-Introduction to Service Oriented ArchitectureSOA unit-3-notes-Introduction to Service Oriented Architecture
SOA unit-3-notes-Introduction to Service Oriented Architecture
 
Message passing ( in computer science)
Message   passing  ( in   computer  science)Message   passing  ( in   computer  science)
Message passing ( in computer science)
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanisms
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Unit 4
Unit 4Unit 4
Unit 4
 
Open Cloud Consortium Overview (01-10-10 V6)
Open Cloud Consortium Overview (01-10-10 V6)Open Cloud Consortium Overview (01-10-10 V6)
Open Cloud Consortium Overview (01-10-10 V6)
 
Topic1 substitution transposition-techniques
Topic1 substitution transposition-techniquesTopic1 substitution transposition-techniques
Topic1 substitution transposition-techniques
 

Semelhante a IT6801-Service Oriented Architecture

Semelhante a IT6801-Service Oriented Architecture (20)

XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
Full xml
Full xmlFull xml
Full xml
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
UNIT-1 Web services
UNIT-1 Web servicesUNIT-1 Web services
UNIT-1 Web services
 
Xml
XmlXml
Xml
 
Unit 3 WEB TECHNOLOGIES
Unit 3 WEB TECHNOLOGIES Unit 3 WEB TECHNOLOGIES
Unit 3 WEB TECHNOLOGIES
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questions
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
 
Xml in bio medical field
Xml in bio medical fieldXml in bio medical field
Xml in bio medical field
 
IT6801-Service Oriented Architecture- UNIT-I notes
IT6801-Service Oriented Architecture- UNIT-I notesIT6801-Service Oriented Architecture- UNIT-I notes
IT6801-Service Oriented Architecture- UNIT-I notes
 
5010
50105010
5010
 
Web Services Part 1
Web Services Part 1Web Services Part 1
Web Services Part 1
 
Xml programming language myassignmenthelp.net
Xml programming  language myassignmenthelp.netXml programming  language myassignmenthelp.net
Xml programming language myassignmenthelp.net
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML
XMLXML
XML
 
XML notes.pptx
XML notes.pptxXML notes.pptx
XML notes.pptx
 
XML
XMLXML
XML
 
Enhanced xml validation using srml01
Enhanced xml validation using srml01Enhanced xml validation using srml01
Enhanced xml validation using srml01
 
XML Unit 01
XML Unit 01XML Unit 01
XML Unit 01
 

Último

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Último (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

IT6801-Service Oriented Architecture

  • 1. IT6801 SERVICE ORIENTED ARCHITECTURE L T P C 3 0 0 3 OBJECTIVES: The student should be made to:  Learn XML fundamentals.  Be exposed to build applications based on XML.  Understand the key principles behind SOA.  Be familiar with the web services technology elements for realizing SOA.  Learn the various web service standards. UNIT I INTRODUCTION TO XML 9 XML document structure – Well formed and valid documents – Namespaces – DTD – XML Schema –X-Files. UNIT II BUILDING XML- BASED APPLICATIONS 9 Parsing XML – using DOM, SAX – XML Transformation and XSL – XSL Formatting – Modeling Databases in XML. UNIT III SERVICE ORIENTED ARCHITECTURE 9 Characteristics of SOA, Comparing SOA with Client-Server and Distributed architectures – Benefits of SOA -- Principles of Service orientation – Service layers. UNIT IV WEB SERVICES 9 Service descriptions – WSDL – Messaging with SOAP – Service discovery – UDDI – Message Exchange Patterns – Orchestration – Choreography –WS Transactions. UNIT V BUILDING SOA-BASED APPLICATIONS 9 Service Oriented Analysis and Design – Service Modeling – Design standards and guidelines -- Composition – WS-BPEL – WS-Coordination – WS-Policy – WS-Security – SOA support in J2EE. TOTAL PERIOD: 45 Periods OUTCOMES: Upon successful completion of this course, students will be able to:  Build applications based on XML.  Develop web services using technology elements.  Build SOA-based applications for intra-enterprise and inter-enterprise applications. TEXTBOOKS: 1. Ron Schmelzer et al. “XML and Web Services”, Pearson Education, 2002 2. Thomas Erl, “Service Oriented Architecture: Concepts, Technology, and Design”, Pearson Education, 2005. REFERENCES: 1. Frank P.Coyle, “XML, Web Services and the Data Revolution”, Pearson Education, 2002. 2. Eric Newcomer, Greg Lomow, “Understanding SOA with Web Services”, Pearson Education, 2005. 3. Sandeep Chatterjee and James Webber, “Developing Enterprise Web Services: An Architect's Guide”, Prentice Hall, 20044. 4. James McGovern,Sameer Tyagi, Michael E.Stevens, Sunil Mathew, ”Java Web. Services Architecture”, Morgan Kaufmann Publishers, 2003.
  • 2. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 1 S.No. Name of the Topic Reference Book (Text Book) UNIT I - INTRODUCTION TO XML 1. XML document structure Chapter 2 (Text 1) 2. Well-formed and valid documents Chapter 2 (Text 1) 3. Namespaces Chapter 2 (Text 1) 4. DTD Chapter 3 (Text 1) 5. 6. XML Schema Chapter 4 (Text 1) 7. 8. X-Files Chapter 5 (Text 1) 9. Content Beyond Syllabus JSON
  • 3. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 2 XML (Extensible Markup Language) XML is a simple, very flexible text format derived from SGML. Originally designed to meet the challenges of large-scale electronic publishing, XML is also playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. Common Uses/Applications of XML  Data Interchange Format Because XML is nonproprietary and easy to read and write, it’s an excellent format for the interchange of data among different applications. Alternative Technologies: JSON (JavaScript Object Notation), YAML  Web development Web documents can be created from XML using XSLT to transform the documents into HTML.  Documentation (or) Document Publishing The term publishing refers to converting a document from a text file that contains XML markup to one or more output files in a specific presentation format, such as HTML, Portable Document Format (PDF), PostScript, Rich Text Format (RTF), and so on. (eg): DocBook (XML vocabulary for representing document contents)  Database Development  Configuration Files Configuration files, or config files configure the parameters and initial settings for some computer programs. They are used for user applications, server processes and operating system settings. (eg): web.xml  Web Services Advantages of XML  Simplicity  Extensibility  Interoperability  Openness  Self-describing
  • 4. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 3 Drawbacks of XML XML takes up lots of space (3 to 20 times more) to represent data that could be similarly modeled using a binary format or a simpler text file format. It’s the price we pay for human- readable, platform-neutral, process-separated, metadata-enhanced, structured, validated code. It’s possible that 1GB of database information can result in over 20GB of XML-encoded information. Introduction to XML Markup Language The main concept behind markup languages is that they use special text strings to surround data or text with information that indicates the context, meaning, or interpretation of the data encapsulated in the markup. In effect, markup languages in general and XML in particular really contain only two kinds of information: markup elements and actual data that are given meaning by these markup elements. Together, these are known as XML text. Markup text has a couple rules. First, it needs to be differentiated from the rest of the document text by a unique set of characters that delineates where the markup information starts and ends. These special characters are known as delimiters. Character Meaning < The start of an XML markup tag > The end of an XML markup tag & The start of an XML entity ; The end of an XML entity Table: XML Delimiter Characters Extensible Extensibility, as applied to XML, is the ability for the language to be used to define specific vocabularies and metadata. Rather than being fixed in describing a particular set of data, XML, in conjunction with its DTDs and schema, is able to define any number of documents that together form a language of their own. It would be a difficult proposition at best to add a new set of information to a text file or relational database management system (RDBMS). XML files, especially those created using an “open content model,” can easily be extended by adding additional elements and attributes.
  • 5. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 4 XML Document Structure The major portions of an XML document include the following:  The XML declaration  The Document Type Declaration  The element data  The attribute data  The character data or XML content XML Declaration The first part of an XML document is the declaration. The XML declaration is a processing instruction of the form <?xml ...?>. Although it is not required, the presence of the declaration explicitly identifies the document as an XML document and indicates the version of XML to which it was authored. In addition, the XML declaration indicates the presence of external markup declarations and character encoding. The standalone document declaration defines whether an external DTD will be processed as part of the XML document. When standalone is set to “yes”, only internal DTDs will be allowed. When it is set to “no”, an external DTD is required and an internal DTD becomes an optional feature <?xml version=“1.0” standalone=“yes” ?> <?xml version=“1.0” standalone=“no” ?> <?xml version=“1.0” encoding=“UTF-8” standalone=“yes” ?>
  • 6. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 5 Document Type Declaration The Document Type Declaration (DOCTYPE) gives a name to the XML content and provides a means to guarantee the document’s validity, either by including or specifying a link to a Document Type Definition (DTD). General Forms of the Document Type Declarations <!DOCTYPE NAME SYSTEM “file”> <!DOCTYPE NAME SYSTEM [ ]> <!DOCTYPE NAME SYSTEM “file” [ ]> In the first form listed, the DOCTYPE is referring to a document that only allows use of an externally defined DTD subset. The second declaration only allows an internally defined subset within the document. The final listing provides a place for inclusion of an internally defined DTD subset between the square brackets while also making use of an external subset. In the preceding listing, the keyword NAME should be replaced with the actual root element contained in the document, and the “file” keyword should be replaced with a path to a valid DTD. Markup and Content In general, six kinds of markup can occur in an XML document: elements, entity references, comments, processing instructions, marked sections, and Document Type Declarations.  Elements Within an XML document, elements are the most common form of markup. XML elements are either a matched pair of XML tags or single XML tags that are “self-closing.” Matching XML tags consist of markup tags that contain the same content, except that the ending tag is prefixed with a forward slash. <regno> Opening Tag / Start Tag </regno> Closing Tag / End Tag When elements do not come in pairs, the element name is suffixed by the forward slash. These “unmatched” elements are known as empty elements. <br/> Empty Elements
  • 7. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 6  Attributes Attributes are name/value pairs contained within the start element that can specify text strings that modify the context of the element. <studentName section =“A”>Rahul</studentName>  Entity References Entities provide a means to indicate to XML-processing applications that a special text string is to follow that will be replaced with a different literal value. CHARACTER REFERENCE & &amp; < &lt; > &gt; “ &quot; ‘ &apos; Table: Built-in Entity References <description>The following says that 8 is greater than5 </description> <equation>4 &gt; 5</equation>  Comments The character sequence <!-- begins a comment and --> ends the comment. Comments can be placed anywhere in a document and are not considered to be part of the textual content of an XML document. As a result, XML processors are not required to pass comments along to an application. <!-- This XML document describes student information -->  Processing Instructions Processing instructions (PIs) are like comments that are intended for computer programs reading the document. However, XML parsers are required to pass along the contents of processing instructions to the application on whose behalf they’re parsing, unlike comments
  • 8. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 7 that a parser is allowed to silently discard. However, the application that receives the information is free to ignore any processing instruction it doesn’t understand. Processing instructions begin with <? and end with ?>. The starting <? is followed by an XML name called the target, which identifies the program that the instruction is intended for, followed by data for that program. Processing instructions have the following form: <?target data?> Eg: <?xml-stylesheet type=”text/xsl” href=”appUsers.xslt” ?> The target in this example is xml-stylesheet.  CDATA CDATA stands for Character Data. CDATA sections provide a way to tell the parser that there is no markup in the characters contained by the CDATA section. This makes it much easier to create documents containing sections where markup characters might appear, but where no markup is intended. Everything inside a CDATA section is ignored by the parser. A CDATA section starts with "<![CDATA[" and ends with "]]>": <example-code> <![CDATA[ while (x <len&& !done) { print( "Still working, 'zzzz'." ); ++x; } ]]> </example-code> Rules of XML Structure All XML Elements Must Have a Closing Tag XML requires all tags to be closed. They can be closed by matching a beginning element tag with a closing tag, or they can be closed by the use of empty elements. In either case, no tag may be left unclosed.
  • 9. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 8 Incorrect XML Due to Unclosed Tags <markup>This is not valid XML <markup>Since there is no closing tag XML Tags Are Case Sensitive In XML, the use of capitalization is incredibly important. XML elements and attributes are case sensitive. This means that differences in capitalization will be interpreted as different elements or attributes. In XML, the elements <student> and <Student> are as different as <egg> and <house>. All XML Elements Must Have Proper Nesting XML requires that elements be nested in proper hierarchical order. Tags must be closed in the reverse order in which they are opened. A proper analogy is to think of XML tags as envelopes. There must never be a case where one envelope is closed when an envelope contained within it is still open. <student> <regno> These tags are improperly nested </student> </regno> All XML Documents Must Contain a Single Root Element XML documents must contain a single root element—no less, and certainly no more. All other elements in the XML document are then nested within this root element. Once the root element is defined, any number of child elements can branch off it as long as they follow the rules. Attribute Values Must Be Quoted When attributes are used within XML elements, their values must be surrounded by quotes. Although most systems accept single or double quotes for attribute values, it is generally accepted to use double quotes around attribute values.
  • 10. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 9 <?xml version=1.0?> <shirt> <price currency=USD>14.99</price> </shirt> Incorrect XML Due to Improper Quoting of Attributes Attributes May Only Appear Once in the Same Start Tag Even though attributes may be optional, when they are present, they can only appear once. This simple restriction prevents ambiguity when multiple, conflicting attribute name/value pairs are present. <shirt size=”large” size=”small”>Zippy Tee</shirt> Incorrect XML Due to Multiple Attribute Names in Start Tag Attribute Values Cannot Contain References to External Entities Although external entities may be allowed for general markup text, attribute values cannot contain references to external entities. However, attribute values can make use of internally defined entities and generally available entities, such as &lt; and &quot;. All Entities Except amp, lt, gt, apos, and quot Must Be Declared Before They Are Used Although this goes without saying, entities cannot be used before they are properly declared. Referring to an undeclared entity would obviously result in an XML document that is not well formed and proper. However, there are a number of entities that can be assumed to be defined by XML processors. So far, these are limited to the entities &amp;, &lt;, &gt;, &apos;, and &quot;. Well-Formed XML Document Well-formed XML document A XML document is well-formed if it conforms to XML specification and it is syntactically correct. Not well-formed:  An element lacks a closing tag (and is not self-closing).
  • 11. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 10  Elements overlap without proper nesting: <a><b></a></b>  An attribute value is missing a closing quote that matches the opening quote.  <or& are used in content rather than &lt or &amp;.  Multiple root elements exist.  Multiple XML declarations exist, or an XML declaration appears other than at the top of the document. XML Processing XML Parser or Processor is a software module that is used to read XML documents and provide access to their content and structure. XML Parser (Validating & Non-Validating) A non-validating parser is required to verify that an input XML document is well formed or not. Non-validating parsers have the advantage that they will generally run faster than validating parsers because they perform less validation. A validating parser requires that any document it parses contain a DTD or XSD. The validating parser will read the DTD or XSD, verify that the document conforms with DTD or XSD, and also verify that the document meets validity constraints defined by the XML recommendation. An advantage of validating parsers is that every correct implementation of a validating parser should produce essentially the same results when parsing a given XML document. XML Vocabulary An XML vocabulary is created by specifying a complete description of the elements and attributes for a specific type of XML document. (Eg) RSS, XSLT, SOAP, SVG etc XML Namespace An XML namespace is a collection of element and attribute names associated with a particular XML vocabulary through an absolute URI known as the namespace name.
  • 12. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 11 Need for XML Namespace It provides a mechanism to avoid name conflicts when XML document may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace, the ambiguity between identically named elements or attributes can be resolved. Example This XML carries HTML table information: <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> This XML carries information about a table (a piece of furniture): <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning. Name conflicts in XML can easily be avoided using a name prefix. <?xml version = "1.0"?> <!-- Demonstrating namespaces --> <!--This XML carries information about an HTML table, and a piece of furniture --> <h:demo
  • 13. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 12 xmlns:h = "http://www.w3schools.com/htmlTableInfo" xmlns:f = "http://www.w3schools.com/furnitureTableInfo"> <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </h:demo> In the example above, there will be no conflict because the two <table> elements have different namespaces.  xmlns is the attribute used to specify the namespace URI.  h and f are namespace prefixes  http://www.w3schools.com/htmlTableInfo andhttp://www.w3schools.com/furnitureTableInfo are namespace URIs. They are unique and need not represent actual webpages. Default Namespace To eliminate the need to place namespace prefixes in each element, document authors may specify a default namespace for an element and its children. <?xml version = "1.0"?> <!-- Demonstrating Default Namespaces --> <!-- This XML carries information about an HTML table, and a piece of furniture -->
  • 14. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 13 <demo xmlns = "http://www.w3schools.com/htmlTableInfo" xmlns:f = " http://www.w3schools.com/furnitureTableInfo"> <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </demo> In the above example, xmlns attribute without namespace prefix specifies default namespace. XML Schema An XML Schema is a language for expressing constraints about XML documents. There are several different schema languages in widespread use, but the main ones are:  Document Type Definitions (DTDs)  XSD (XML Schema Definitions)  Relax-NG  Schematron DTD A document type definition lists the elements, attributes, entities, and notations that can be used in a document, as well as their possible relationships to one another. A DTD specifies a set of rules for the structure of a document. A DTD can be declared inside an XML document or in an external file.  Internal DTD: DTD is declared inside the XML file.
  • 15. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 14  External DTD: DTD is declared in an external file. The Document Type Declaration A document type declaration begins with <!DOCTYPE and ends with a >. In between is the name of the root element, followed either by a pair of square brackets containing the DTD itself or by the SYSTEM keyword and a URL where the DTD can be found (or, occasionally, both). A document type declaration has this basic form: <!DOCTYPE rootelement SYSTEM | PUBLIC DTDlocation [ internalDTDelements ] >  The exclamation mark (!) is used to signify the beginning of the declaration.  DOCTYPE is the keyword used to denote this as a Document Type Definition.  rootelement is the name of the root element or document element of the XML document.  SYSTEM and PUBLIC are keywords used to designate that the DTD is contained in an external document. Although the use of these keywords is optional, to reference an external DTD you would have to use one or the other. The SYSTEM keyword is used in tandem with a URL to locate the DTD. The PUBLIC keyword specifies some public location that will usually be some application-specific resource reference.  internalDTDelements are internal DTD declarations. These declarations will always be placed within opening ([) and closing (]) brackets. DTD Elements  Each element in the DTD should be defined with the following syntax: <!ELEMENT elementname rule > o ELEMENT is the tag name that specifies that this is an element definition. o elementname is the name of the element. o rule is the definition to which the element’s data content must conform.  Elements are declared using element declarations. Each element declaration gives the name of the element and lists the elements and text that it can contain. This list is called the content specification. For example, this element declaration for the firstName element says that elements with the name firstName must contain only parsed character data: <!ELEMENT firstName (#PCDATA)>
  • 16. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 15 Every declaration begins with <!. Element declarations begin with <!ELEMENT(case- sensitive, as most things are in XML). This is followed by some white space and the name of the element being declared, firstName in this example.  The content spec (#PCDATA) says that the element must contain parsed character data. Parsed character data is essentially any text that’s not markup. This also includes entity references, such as &amp;, that are replaced by text when the document is parsed. employee.dtd <!ELEMENT Employees (employee*)> <!ELEMENT employee (employeeName, employeeID, dateOfBirth, address)> <!ELEMENT employeeName (firstName, lastName)> <!ELEMENT employeeID (#PCDATA)> <!ELEMENT dateOfBirth (month, date, year)> <!ELEMENT address (city, state)> <!ELEMENT firstName (#PCDATA)> <!ELEMENT lastName (#PCDATA)> <!ELEMENT month (#PCDATA)> <!ELEMENT date (#PCDATA)> <!ELEMENT year (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> employee.xml <?xml version="1.0"?> <!DOCTYPE Employees SYSTEM "employee.dtd"> <Employees> <employee> <employeeName> <firstName>Rahul</firstName> <lastName>Dravid</lastName> </employeeName> <employeeID>5012</employeeID>
  • 17. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 16 <dateOfBirth> <month>January</month> <date>11</date> <year>1973</year> </dateOfBirth> <address> <city>Bangalore</city> <state>Karnataka</state> </address> </employee> </Employees> DTD Element Rules There are two basic types of rules that elements must fall into. The first type of rule deals with content. The second type of rule deals with structure.  Content Rules: The content rules for .elements deal with the actual data that defined elements may contain. These rules include the ANY rule, the EMPTY rule, and the #PCDATA rule. o The ANY Rule An element may be defined using the ANY rule. This rule is just what it sounds like: The element may contain other elements and/or normal character data (just about anything as long as it is well formed). An element using the ANY rule would appear as follows: <!ELEMENT elementname ANY> o The EMPTY Rule This rule is the exact opposite of the ANY rule. An element that is defined with this rule will contain no data. However, an element with the EMPTY rule could still contain attributes (more on attributes in a bit). The following element is an example of the EMPTY rule: <!ELEMENT elementname EMPTY> o The #PCDATA Rule
  • 18. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 17 The #PCDATA rule indicates that parsed character data will be contained in the element. Parsed character data is data that may contain normal markup and will be interpreted and parsed by any XML parser accessing the document. The following element demonstrates the #PCDATA rule: <!ELEMENT elementname (#PCDATA)>  Structure Rules: The structure rules deal with how that data may be organized. There are two types of structure rules we will look at here. The first is the “element only” rule. The second rule is the “mixed” rule. o The “Element Only” Rule The “element only” rule specifies that only elements may appear as children of the current element. The child element sequences should be separated by commas and listed in the order they should appear. If there are to be options for which elements will appear, the listed elements should be separated by the pipe symbol. <!ELEMENT elementname (element1, element2, element3)> <!ELEMENT elementname (element1 | element2)> o The “Mixed” Rule The “mixed” rule is used to help define elements that may have both character data (#PCDATA) and child elements in the data they contain. A list of options or a sequential list will be enclosed by parentheses. Options will be separated by the pipe symbol (|), whereas sequential lists will be separated by commas. <!ELEMENT elementname (#PCDATA | childelement1 | childelement2)*> Element Symbols Asterisk (*) The data will appear zero or more times (0, 1, 2, …). <!ELEMENT Employees (employee*)> Plus sign (+) Signifies that the data must appear one or more times (1, 2, 3, …). <!ELEMENT Employees (employee+)> Question mark (?) Data will appear either zero times or one time in the element. <!ELEMENT Employees (employee?)>
  • 19. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 18 Pipe (|) Separates choices in a set of options. <!ELEMENT accountType (savings | current | termDeposit)> DTD Attributes Attribute list declarations in a DTD will have the following syntax: <!ATTLIST elementname attributename type defaultbehavior defaultvalue>  ATTLIST is the tag name that specifies that this definition will be for an attribute list.  elementname is the name of the element that the attribute will be attached to.  attributename is the actual name of the attribute.  type indicates which of the 10 valid kinds of attributes this attribute definition will be.  defaultbehavior dictates whether the attribute will be required, optional, or fixed in value. This setting determines how a validating parser should relate to this attribute.  defaultvalue is the value of the attribute if no value is explicitly set. <!ATTLIST employeeName gender CDATA #REQUIRED country CDATA #IMPLIED > ATTLIST Declaration An XML element using the attribute list declared here would appear as follows: <employeeName gender = “male” country = “India”> <firstName>Rahul</firstName> <lastName>Dravid</lastName> </employeeName> DTD Entities Entities in DTDs are storage units. They can also be considered placeholders. Entities are special markups that contain content for insertion into the XML document. Usually this will be some type of information that is bulky or repetitive. Entities make this type of information more easily handled because the DTD author can use them to indicate where the information should be
  • 20. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 19 inserted in the XML document. This is much better than having to retype the same information over and over. The general syntax of an entity is as follows: <!ENTITY entityname [SYSTEM | PUBLIC] entitycontent>  ENTITY is the tag name that specifies that this definition will be for an entity.  entityname is the name by which the entity will be referred in the XML document.  entitycontent is the actual contents of the entity—the data for which the entity is serving as a placeholder.  SYSTEM and PUBLIC are optional keywords. Either one can be added to the definition of an entity to indicate that the entity refers to external content. Internal Entity DTD <!ENTITY cpy “Copyright RMKCET 2017”> Usage: <copyright>&cpy;</copyright> When the XML document containing the above content is parsed, &cpy; will be replaced with “Copyright RMKCET 2017” in each instance in which it is used. Using the entity &cpy; saves the XML document author from having to type in “Copyright RMKCET 2017” over and over. External Entities External entities are used to reference external content. DTD <!ENTITY rahul SYSTEM “http://srvr/emps/rahul.xml”> Usage: <staff>&rahul;</staff> Non-Text External Entities and Notations Some external entities will contain non-text data, such as an image file. We do not want the XML parser to attempt to parse these types of files. The NDATA keyword is used to alert the parser that the entity content should be sent unparsed to the output document.
  • 21. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 20 A notation is a special declaration that identifies the format of non-text external data so that the XML application will know how handle the data. <!NOTATION gif SYSTEM “image/gif” > <!ENTITY employeephoto SYSTEM “images/employees/rahul.gif” NDATA gif > <!ELEMENT employee (name, sex, title, years) > <!ATTLIST employee pic ENTITY #IMPLIED > … <employee pic=”employeephoto”> … </employee> Parameter Entities It is very similar to the internal entity. The main difference between an internal entity and a parameter entity is that a parameter entity may only be referenced inside the DTD. Parameter entities can be useful when you have to use a lot of repetitive or lengthy text in a DTD. Use the following syntax for parameter entities: <!ENTITY % entityname entitycontent> The syntax for a parameter entity is almost identical to the syntax for a normal, internal entity. However, notice that in the syntax, after the declaration, there is a space, a percent sign, and another space before entityname. This alerts the XML parser that this is a parameter entity and will be used only in the DTD. These types of entities, when referenced, should begin with % and end with;. Drawbacks of DTD  DTDs are composed of non-XML syntax and are non-extensible.  There can only be a single DTD per document.  DTDs are not object oriented. There is no inheritance in DTDs.  DTDs have weak data typing. DTDs basically have one data type: the text string.  DTDs does not support namespace very well.  Number and order of child elements is not properly supported by DTD.
  • 22. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 21 XSD The W3C XML Schema Definition Language (XSD) is an XML language for describing and constraining the content of XML documents. W3C XML Schema is a W3C Recommendation. Built-in Data Types Some of the XSD Built-in data types: Namespace URI for XML Schema: http://www.w3.org/2001/XMLSchema An element declaration in an XSD schema <element name="RegisterNumber" type="xsd:integer"/> The usage of this element in an XML document instance. <RegisterNumber>12345</ RegisterNumber> User-Defined Simple Types A simple element is an XML element that contains only text. It cannot contain any other elements or attributes. The text can be of many different types. It can be one of the types XML Schema Type Java Data Type xsd:string java.lang.String xsd:integer java.math.BigInteger xsd:int int xsd.long long xsd:short short xsd:decimal java.math.BigDecimal xsd:float float xsd:double double xsd:boolean boolean xsd:byte byte
  • 23. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 22 included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself. One can also add restrictions (facets) to a data type in order to limit its content, or one can require the data to match a specific pattern. Example: Defining marks, Range 0-100 <xsd:simpleType name="marks"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="0"/> <xsd:maxInclusive value="100"/> </xsd:restriction> </xsd:simpleType> Facets in XSD  enumeration  fractionDigits  length  maxExclusive  maxInclusive  maxLength  minExclusive  minInclusive  minLength  pattern Besides <restriction> element, <simpleType> element has <list> and <union> child elements. The <list> element allows an element or attribute based on the type definition to contain a list of values of a specified simple data type. The <union> element allows you to combine two or more simple type definitions to create a collection of values. User-Defined Complex Types XSD schema declaration <complexType name="Student"> <sequence> <element name="RegisterNumber" type="xsd:integer"/> <element name="StudentName" type="xsd:string"/> <element name="DepartmentName" type="xsd:string"/>
  • 24. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 23 <element name="CGPA" type="xsd:decimal"/> </sequence> </complexType> Order Indicators sequence the elements must appear in the order specified all the elements must appear, but order is not important choice specifies that either one child element or another can occur Occurrence Indicators maxOccurs specifies the maximum number of times an element can occur minOccurs specifies the minimum number of times an element can occur Group Indicators Group Defines set of related elements attributeGroup Defines set of related attributes Table: XSD Indicators  <xsd:simpleContent> is used when you have an element that can contain structural markup (complexType) and the element is not allowed to contain child elements. In other words the elements content type allows only attributes and text content. <?xml version="1.0" encoding="UTF-8" ?> <!-- book.xsd --> <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="books"> <xs:complexType> <xs:sequence> <xs:element name="book" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="bookname" type="xs:string"/>
  • 25. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 24 <xs:element name="isbn" type="xs:string"/> <xs:element name="authorname"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="publishername" type="xs:string"/> <xs:element name="bookprice"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:decimal"> <xs:attribute name="currency" type="xs:string" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
  • 26. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 25 <?xml version="1.0"?> <!-- book.xml --> <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd"> <book> <bookname>Internet and World Wide Web How to Program</bookname> <isbn>ISBN-10: 0-13-215100-6</isbn> <authorname> <firstname>Paul J</firstname> <lastname>Deitel</lastname> </authorname> <publishername>Deitel and Associates, Inc</publishername> <bookprice currency="rupees">11486</bookprice> </book> <book> <bookname>Java: The Complete Reference</bookname> <isbn>ISBN-10: 9339212096</isbn> <authorname> <firstname>Herbert</firstname> <lastname>Schildt</lastname> </authorname> <publishername>McGraw Hill</publishername> <bookprice currency="rupees">539</bookprice> </book> </books>
  • 27. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 26 XFiles: XPath, XPointer and XLink XPath XPath is a syntax for specifying a collection of elements or other information contained within an XML document. Conceptually, XPath assumes that the XML document to which XPath expressions will be applied has been parsed into an internal tree representation. The XPath tree model is similar to the DOM tree. For example, the nodes in an XPath tree are of different types, such as element, text, and comment nodes. In addition, unlike the DOM model, the XPath tree model also uses nodes to represent attribute name value pairs. The root of the XPath parse tree is known as the document root. Like an instance of Document in the DOM, this node of the XPath parse tree has a child node representing the root of the element hierarchy in the parsed document; this node is called the document element. Location Path An XPath expression that represents one or more nodes within an XPath parse tree is known as a location path. A location path can be absolute or relative. An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases the location path consists of one or more location steps, each separated by a slash: An absolute location path: /step/step/... A relative location path: step/step/... Each step is evaluated against the nodes in the current node-set.A step consists of:  an axis (defines the tree-relationship between the selected nodes and the current node)  a node-test (identifies a node within an axis)  zero or more predicates (to further refine the selected node-set) The syntax for a location step is: axisname::nodetest[predicate]
  • 28. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 27 Table: Some XPath 1.0 Axis Names Example Result child::book Selects all book nodes that are children of the current node attribute::lang Selects the lang attribute of the current node child::* Selects all element children of the current node attribute::* Selects all attributes of the current node child::text() Selects all text node children of the current node child::node() Selects all children of the current node descendant::book Selects all book descendants of the current node ancestor::book Selects all book ancestors of the current node
  • 29. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 28 ancestor-or- self::book Selects all book ancestors of the current node - and the current as well if it is a book node child::*/child::price Selects all price grandchildren of the current node Table: XPath Axis Name Examples <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book>
  • 30. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 29 <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> Program: books.xml Example XPath Expressions  /bookstore/book/title - selects all the title nodes  /bookstore/book[1]/title - selects the title of the first book node under the bookstore element  /bookstore/book/price[text()] - selects the text from all the price nodes  /bookstore/book[price>35]/price - selects all the price nodes with a price higher than 35  /bookstore/book[price>35]/title - selects all the title nodes with a price higher than 35 XPointer The XML Pointer Language (XPointer) builds on the XPath specification. An XPointer uses location steps the same as XPath but with two major differences: Because an XPointer describes a location within an external document, an XPointer can target a point within that XML document or a range within the target XML document. Because XPointer builds on the XPath specification, the location steps within an XPointer are comprised of the same elements that make up XPath location steps. In addition to the node tests already listed for XPath expressions, XPointer provides two more important node tests:  point()  range() For this new functionality to work correctly, the XPointer specification added the concept of a location within an XML document. Within XPointer, a location can be an XPath node, a point, or
  • 31. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 30 a range. A point can represent the location immediately before or after a specified character or the location just before or just after a specified node. A range consists of a start point and an end point and contains all XML information between those two points. XPointer expressions also allow predicates to be specified as part of a location step in much the same fashion XPath expressions allow for them. For an XPath expression, the result from a location step is known as a node set; for an XPointer expression, the result is known as a location set. <People> <Person> <Name>Dillon Larsen</Name> <Address> <Street>123 Jones Rd.</Street> <City>Houston</City> <State>TX</State> <Zip>77380</Zip> </Address> </Person> <Person> <Name>Madi Larsen</Name> <Address> <Street>456 Hickory Ln.</Street> <City>Houston</City> <State>TX</State> <Zip>77069</Zip> </Address> </Person> <Person> <Name>John Doe</Name> <Address> <Street>214 Papes Way</Street>
  • 32. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 31 <City>Houston</City> <State>TX</State> <Zip>77301</Zip> </Address> </Person> </People> XPointer Expression Location /People/Person[1]/Name/text()/point()[position()=4] Just after the l and just before the start o in Dillon /People/Person[1]/Name/text()/start- point()[position()=0] Just before the D in Dillon /People/Person[2]/Address/ start-point()[position()=2] Just before the <State> element in the <Person> element for Madi Larsen /People/Person[2]/Address/ start-point()[position()=0] Just before the <Street> element in the <Person> element for Madi Larsen XLink The XML Linking Language, XLink, allows a link to another document to be specified on any element within an XML document. The XML Linking Language creates a link to another resource through the use of attributes specified on elements, not through the actual elements themselves. Attribute Description xlink:type This attribute must be specified and indicates what type of XLink is represented or defined. xlink:href This attribute contains the information necessary to locate the desired resource. xlink:role This attribute describes the function of the link between the current resource and another. xlink:arcrole This attributes describes the function of the link between the current resource and
  • 33. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 1 - CSE/RMKCET 32 another. xlink:title This attribute describes the meaning of the link between the resources. xlink:show This attribute indicates how the resource linked to should be displayed. xlink:actuate This attribute specifies when to load the linked resource. xlink:label This attribute is used to identify a name for a target resource. xlink:from This attribute identifies the starting resource. xlink:to This attribute identifies the ending resource. Further Reading 1. Validating XML document against XSD. https://stackoverflow.com/questions/124865/xml-schema-xsd-validation-tool
  • 34. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 1 S.No. Name of the Topic Reference Book(Text Book) UNIT II - BUILDING XML- BASED APPLICATIONS 1. Parsing XML using DOM Chapter 7 (Text 1) 2. 3. Parsing XML using SAX Chapter 8 (Text 1) 4. 5. XML Transformation and XSL Chapter 9 (Text 1) 6. 7. XSL Formatting Chapter 9 (Text 1) 8. Modeling Databases in XML Chapter 10 (Text 1) 9.
  • 35. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 2 XML Processing XML Parser or Processor is a software module that is used to read XML documents and provide access to their content and structure. DOM The Document Object Model is a platform- and language-neutral standard application programming interface (API) that will allow programs and scripts to dynamically access and update the content, structure and style of documents. It is a W3C recommendation. In DOM-based XML processing, an XML document is first input and parsed, creating a tree of nodes representing elements, text, comments, and so on. After the tree has been constructed, methods can be called to modify the tree, extract data from it, and so on. DOM Levels The DOM working group works on phases (or levels) of the specification.  Level 1 allows traversal of an XML document as well as the manipulation of the content in that document.  Level 2 extends Level1 with additional features such as namespace support, events, ranges, and so on.  Level 3 extends Level 2. It provides features for loading and saving documents and validation. DOM Core The DOM core is available in DOM Level 1 and beyond. It permits you to create and manipulate XML documents in memory. DOM is a tree structure that represents elements, attributes, and content. DOM Interfaces The DOM interfaces are defined in IDL so that they are language neutral.
  • 36. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 3 Fig: Interface relationships.
  • 37. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 4 Class Description DocumentBuilder Defines the API to obtain DOM Document instances from an XML document. DocumentBuilderFactory Defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents. JAXP provides a unified approach to creating parser instances through a factory mechanism. A factory is just an object that is used to create other objects. <?xml version="1.0"?> <!DOCTYPE Employees SYSTEM "employee.dtd"> <?xml-stylesheet type="text/xsl" href="employeestyle.xsl" ?> <Employees> <employee> <employeeName> <firstName>Rahul</firstName> <lastName>Dravid</lastName> </employeeName> <employeeID>5012</employeeID> <dateOfBirth> <month>January</month> <date>11</date> <year>1973</year> </dateOfBirth> <address> <city>Bangalore</city> <state>Karnataka</state> </address> </employee> <employee> <employeeName>
  • 38. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 5 <firstName>Sachin</firstName> <lastName>Tendulkar</lastName> </employeeName> <employeeID>5001</employeeID> <dateOfBirth> <month>April</month> <date>24</date> <year>1973</year> </dateOfBirth> <address> <city>Mumbai</city> <state>Maharashtra</state> </address> </employee> </Employees> Program: employee.xml package xml; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class DOMDemo { protected DocumentBuilder documentBuilder; protected Element root;
  • 39. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 6 public DOMDemo() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilder = documentBuilderFactory.newDocumentBuilder(); } public static void main(String[] args) throws Exception { String fileName = "employee.xml"; DOMDemo dom = new DOMDemo(); dom.parse(fileName); dom.printAllElements(); } public void parse(String fileName) throws Exception { File inputFile = new File(fileName); Document doc = documentBuilder.parse(inputFile); root = doc.getDocumentElement(); System.out.println("Root element is:" + root.getNodeName()); } public void printAllElements() throws Exception { printElement("", root); } public void printElement(String indent, Node aNode) { if (aNode.getNodeType() == Node.TEXT_NODE) { System.out.println(indent + aNode.getNodeValue()); } else {
  • 40. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 7 System.out.println(indent + "<" + aNode.getNodeName() + ">"); Node child = aNode.getFirstChild(); while (child != null) { printElement(indent + "t", child); child = child.getNextSibling(); } System.out.println(indent + "</" + aNode.getNodeName() + ">"); } } } Program: DOMDemo.java
  • 41. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 8 Creating an XML Document package xml; import java.io.File; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.*; public class DOMCreationDemo { public static final String xmlFilePath = "company.xml"; public static void main(String argv[]) { try {
  • 42. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 9 DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); // root element Element root = document.createElement("company"); document.appendChild(root); // employee element Element employee = document.createElement("employee"); root.appendChild(employee); // set an attribute to staff element Attr attr = document.createAttribute("id"); attr.setValue("10"); employee.setAttributeNode(attr); // firstname element Element firstName = document.createElement("firstname"); firstName.appendChild(document.createTextNode("Sachin")); employee.appendChild(firstName); // lastname element Element lastname = document.createElement("lastname"); lastname.appendChild(document.createTextNode("Tendulkar")); employee.appendChild(lastname); // email element Element email = document.createElement("email"); email.appendChild(document.createTextNode("sachin.tendulkar@gmail .com")); employee.appendChild(email); // department elements
  • 43. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 10 Element department = document.createElement("department"); department.appendChild(document.createTextNode("Batting")); employee.appendChild(department); // create the xml file // transform the DOM Object to an XML File TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(document); StreamResult streamResult = new StreamResult(new File(xmlFilePath)); transformer.transform(domSource, streamResult); System.out.println("Done creating XML File"); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } } } DOM Traversal and Range Traversal and range are features added in DOM Level 2.You can determine whether traversal is supported by calling the hasFeature()method of the DOMImplementation interface. For traversal, you can use the arguments“Traversal” and “2.0” for the feature and version parameters of the hasFeature()method. Traversal Traversal is a convenient way to walk through a DOM tree and select specific nodes.This is useful when you want to find certain elements and perform operations on them.
  • 44. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 11 Interface Description NodeIterator Used to walk through nodes linearly. Represents a subtreeas a linear list. TreeWalker Represents a subtree as a tree view. NodeFilter Can be used in conjunction with NodeIterator andTreeWalker to select specific nodes. DocumentTraversal Contains methods to create NodeIterator andTreeWalker instances. Table: Summary of Traversal Interfaces Range Range interfaces provide a convenient way to select, delete, extract, and insert content. You can determine whether range is supported by calling the hasFeature(...) method of the DOMImplementation interface. You can use the arguments “Range” and “2.0” for feature and version. There are a number of applications for which the range interfaces are useful. A range consists of two boundary points corresponding to the start and the end of the range. A boundary point’s position in a Document or DocumentFragment tree can be characterized by a node and an offset. The node is the container of the boundary point and its position. The container and its ancestors are the ancestor containers of the boundary point and its position. The offset within the node is the offset of the boundary point and its position. If the container is an Attr, Document, DocumentFragment, Element, or EntityReference node, the offset is between its child nodes. If the container is a CharacterData, Comment, or ProcessingInstruction node, the offset is between the16-bit units of the UTF-16 encoded string contained by it. Interface Description Range This interface describes a range and contains methods to define, delete, insert content. DocumentRange This interface creates a range. Table: Summary of Range Interfaces DOM Implementations The DOM working group supplies Java language bindings as part of the DOM specification. The specification and Java language bindings are available at the W3C Web site. These bindings are sets of Java source files containing Java interfaces, and they map exactly to the DOM interfaces.
  • 45. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 12 The package org.w3c.dom contains the Java interfaces but does not include a usable implementation. In order to make the interfaces do something useful, you will need an implementation, or a parser. A number of DOM implementations are available for Java. Java APIs for XML Processing (JAXP) The Java API for XML Processing or JAXP is one of the Java XML Application programming interfaces (API). It provides the capability of validating and parsing XML documents. javax.xml.parsers: The JAXP APIs, which provide a common interface for different vendors' SAX and DOM parsers. Xerces JDOM Small DOM-like Implementations Meant for smaller devices.  NanoXML  TinyXML  kXML SAX – Event Oriented Parsing  SAX (Simple API for XML) is an API that can be used to parse XML documents.  SAX provides a framework for defining event listeners, or handlers. These handlers are written by developers interested in parsing documents with a known structure. The handlers are registered with the SAX framework in order to receive events. Events can include start of document, start of element, end of element, and so on. The handlers contain a number of methods that will be called in response to these events. Once the handlers are defined and registered, an input source can be specified and parsing can begin. Class Description SAXParser Defines the API that wraps an XMLReader implementation class. SAXParserFactory Defines a factory API that enables applications to configure and obtain a SAX based parser to parse XML documents. Table: javax.xml.parsers
  • 46. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 13 The basic steps to perform SAX Parsing to an XML Document are:  Create an new instance of SAXParserFactory  Use the appropriate handlers to hand the events of the parsing process by extending the DefaultHandler class  Create the appropriate callback functions to handle the events, e.g. when a new element is found package xml; import java.io.File; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class SAXDemo extends DefaultHandler { public void startDocument() { System.out.println("***Start of Document***"); } public void endDocument() { System.out.println("***End of Document***"); } public void startElement(String uri, String localName, String qName, Attributes attributes) { System.out.print("<" + qName); int n = attributes.getLength();
  • 47. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 14 for (int i = 0; i < n; i += 1) { System.out.print("" + attributes.getQName(i) + "='" + attributes.getValue(i) + ""); } System.out.println(">"); } public void characters(char[] ch, int start, int length) { System.out.println(new String(ch, start, length).trim()); } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { System.out.println("</" + qName + ">"); } public static void main(String args[]) throws Exception { String fileName = "employee.xml"; SAXDemo handler = new SAXDemo(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(new File(fileName), handler); } }
  • 48. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 15
  • 49. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 16 ErrorHandler contains three methods that can be used to determine whether a document iswell formed and valid.Either error() or warning() will be called if the document is well formed but not valid(that is, it violates the rules of the DTD), and fatalError() will be called if the documentis not well formed. /*SAX Validation*/ package xml; import java.io.FileReader; import org.xml.sax.InputSource;
  • 50. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 17 import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; public class SAXValidationDemo extends DefaultHandler { private boolean valid; private boolean wellFormed; public SAXValidationDemo() { valid = true; wellFormed = true; } public void startDocument() { System.out.println("***Start of Document***"); } public void endDocument() { System.out.println("***End of Document***"); } public void error(SAXParseException e) { valid = false; } public void fatalError(SAXParseException e) { wellFormed = false; }
  • 51. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 18 public void warning(SAXParseException e) { valid = false; } public boolean isValid() { return valid; } public boolean isWellFormed() { return wellFormed; } public static void main(String args[]) throws Exception { XMLReader parser = XMLReaderFactory.createXMLReader(); SAXValidationDemo handler = new SAXValidationDemo(); parser.setContentHandler(handler); parser.setErrorHandler(handler); parser.parse(new InputSource(new FileReader("employee.xml"))); if (!handler.isWellFormed()) { System.out.println("Document is NOT well formed."); } if (!handler.isValid()) { System.out.println("Document is NOT valid."); } if (handler.isWellFormed() && handler.isValid()) { System.out.println("Document is well formed and valid."); } } }
  • 52. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 19 Lexical Events LexicalHandler interface, part of org.xml.sax.ext package, is used to capture events like comments, CDATA and DTD references. Comparing DOM and SAX S.No. DOM SAX 1 Tree Based: The DOM parser first read and parse anentire XML document into a tree representation and then process this tree. Event Based: The SAX parser interact with an application as itreads an XML document. As an XML parser is reading an XML document, certainevents occur. 2 More CPU time& Memory:Theentire document tree must be created, even if only a fraction of the document is actuallyrelevant to the software processing the document. Hence consumes more CPU power and memory. Less CPU time & Memory: Only the relevant element is parsed at a time. It consumes less CPU power and memory
  • 53. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 20 JAXB Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. As part of this process, JAXB provides methods for unmarshalling (reading) XML instance documents into Java content trees, and then marshalling (writing) Java content trees back into XML instance documents. JAXB also provides a way to generate XML schema from Java objects. The general steps in the JAXB data binding process are: 1. Generate classes: An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema. xjc: JAXB tool that compiles an XML schema file into fully annotated Java classes Customizing in JAXB2.0 xjc -b <file> <schema> Eg: xjc schema1.xsd schema2.xsd schema3.xsd -b bindings123.xjb
  • 54. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 21 2. Compile classes: All of the generated classes, source files, and application code must be compiled. 3. Unmarshal: XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework. Note that JAXB also supports unmarshalling XML data from sources other than files/documents, such as DOM nodes, string buffers, SAX Sources, and so forth. 4. Generate content tree: The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents. 5. Validate (optional): The unmarshalling process optionally involves validation of the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, below, you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document. 6. Process content: The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler. 7. Marshal: The processed content tree is marshalled out to one or more XML output documents. The content may be validated before marshalling. 8. Comparing with DOM and SAX  DOM: JAXB is faster and requires less memory when compared with DOM.  SAX: There is no need to create and use a parser and no need to write a content handler with callback methods. What this means is that developers can access and process XML data without having to know XML or XML processing. <!--address.xml--> <address> <name>Ajeeth</name> <company>Google</company> <phone>(011) 123-4567</phone> </address>
  • 55. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 22 /*POJO mapped to XML using set of JAXB annotations*/ package xml; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "address") public class Address { private String name; private String company; private String phone; public String getName() { return name; } @XmlElement(name = "name") public void setName(String name) { this.name = name; } public String getCompany() { return company; } @XmlElement(name = "company") public void setCompany(String company) { this.company = company; } public String getPhone() {
  • 56. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 23 return phone; } @XmlElement(name = "phone") public void setPhone(String phone) { this.phone = phone; } @Override public String toString() { return "Address [name=" + name + ", company=" + company + ", phone=" + phone + "]"; } } /*Unmarshaling – XML to Java*/ package xml; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class JAXBUnmarshalDemo { public static void main(String[] args) { try {
  • 57. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 24 File file = new File("address.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Address.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Address address = (Address) jaxbUnmarshaller.unmarshal(file); System.out.println(address); } catch (JAXBException e) { e.printStackTrace(); } } } Output Address [name=Ajeeth, company=Google, phone=(011) 123-4567] /*Marshaling – Java Objects to XML*/ package xml; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class JAXBMarshalDemo { public static void main(String[] args) { Address address = new Address(); address.setName("Rahul Dravid"); address.setCompany("Rajasthan Royals"); address.setPhone("99999 88888"); try { File file = new File("address.xml");
  • 58. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 25 JAXBContext jaxbContext = JAXBContext.newInstance(Address.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //File Output jaxbMarshaller.marshal(address, file); //Console Output jaxbMarshaller.marshal(address, System.out); } catch (JAXBException e) { e.printStackTrace(); } } } Output S.No. Methods Description 1 public abstract Marshaller createMarshaller() throws Create a Marshaller object that can be used to convert a java content tree into XML data.
  • 59. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 26 JAXBException 2 public abstract Unmarshaller createUnmarshaller() throws JAXBException Create an Unmarshaller object that can be used to convert XML data into a java content tree. 3 public static void marshal(Object jaxbObject, File xml) Writes a Java object tree to XML and store it to the specified location. 4 public static JAXBContext newInstance(Class... classesToBeBound) throws JAXBException Obtain a new instance of a JAXBContext class. Annotation Type Description @XmlRootElement(name=”Student”) Maps a class or an enum type to an XML element. @XmlElement(name=”regno”) Maps a JavaBean property to a XML element derived from property name. @XmlAttribute Maps a JavaBean property to a XML attribute. XSL XSL is a family of recommendations for defining XML document transformation and presentation. It consists of three parts:  XSL Transformations (XSLT): It is a language for transforming XML.  The XML Path Language (XPath): It is an expression language used by XSLT (and many other languages) to access or refer to parts of an XML document.  XSL Formatting Objects (XSL-FO): It is an XML vocabulary for specifying formatting semantics. ExtensibleStylesheet Language (XSL) is a “programming language” that allows extraction of information from oneXMLtext documentand uses that information to create another XML text
  • 60. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 27 document.XSL is an XML vocabulary; that is, XSL documents arewell-formed XML documents. So the transformation “program” is an XML document. AnXSL document normally contains two types of information: template data, which is textthat is copied to the output XML text document with little or no change; and XSL markup,which controls the transformation process. XSLT: Template-based Transformation  First, the root element of an XSLT document can be named either transform or stylesheet. There is no semantic difference between these elements.  The content of the root element often consists of one or more template elements. Each template represents a template rule, which typically consists of two parts: o An XPath expression specified as the value of the template element’s match attribute and known as the template rule’s pattern. o The content of the template rule, which is known as the template portion of the rule.  Software for performing an XSLT transformation, such as JAXP, is known as an XSLT processor. An XSLT processor is given two inputs—an XSLT document and asource XML document—and produces a single result XML document. Internally, an XSLTprocessor represents each of these documents as an XPath tree, called the source tree, thestyle-sheet
  • 61. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 28 tree, and the result tree, respectively. Since all three trees are XPath trees, nodes in any of these trees can be referenced using XPathexpressions. <?xml version="1.0" encoding="utf-8" ?> <!-- student.xml --> <?xml-stylesheet type="text/xsl" href="studentstyle.xsl" ?> <students> <student> <registernumber>1001</registernumber> <name>Badrinath</name> <cgpa>8.1</cgpa> </student> <student> <registernumber>1002</registernumber> <name>Dhoni</name> <cgpa>6.5</cgpa> </student> <student> <registernumber>1003</registernumber> <name>Rahul</name> <cgpa>9.6</cgpa> </student> <student> <registernumber>1004</registernumber> <name>Sachin</name> <cgpa>8.8</cgpa> </student> <student> <registernumber>1005</registernumber> <name>Sehwag</name>
  • 62. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 29 <cgpa>8.9</cgpa> </student> <student> <registernumber>1006</registernumber> <name>Yuvraj</name> <cgpa>9.1</cgpa> </student> </students> Program: XML document (Source Tree) <?xml version="1.0" encoding="utf-8" ?> <!-- studentstyle.xsl --> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="students"> <html><head><title>Style Sheet for student.xml</title></head><body> <table border="1" align="center"> <tr style="background-color:khaki;color:blue;"> <th>REGISTER NUMBER</th> <th>NAME</th> <th>CGPA</th> </tr> <xsl:for-each select="student"> <xsl:sort select="cgpa" data-type="number" order="descending" /> <tr> <td><xsl:value-of select="registernumber" /></td> <td><xsl:value-of select="name" /></td> <td><xsl:value-of select="cgpa" /></td> </tr> </xsl:for-each>
  • 63. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 30 </table> </body></html> </xsl:template> </xsl:stylesheet> Program: XSL transformation to represent XML document as HTML Table <xsl: template> Contains rule to apply when a specified node is matched. <xsl: value-of select=”expression”> Selects the value of an XML document and adds it to the output tree of the transformation. The required select attribute contains an XPath expression. <xsl: for-each select=”expression”> Applies a template to every node selected by the XPath specified by the select attribute. <xsl: sort select=”expression”> Used as a child element of an <xsl:apply-templates> or <xsl: for-each> element. Sorts the nodes selected by the <xsl: apply-template> or <xsl: for-each> element so that the nodes are processed in sorted order. <xsl: apply templates> Applies the templates of the XSL document to the children of the current node. <xsl: apply-templates match=”expression”> Applies the templates of the XSL document to the children of expression. The value of the attribute match(i.e., expression) must be an XPath expression that specifies elements. <xsl:iftest = “boolean-expression”> Used to perform conditional statements against the contents of the XML document. Table: XSL Elements
  • 64. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 31 XSL for Business-to-Business (B2B) Communication XSLT can also be used in for B2B communication—the process of exchanging data between two different companies. Developers can leverage XML to describe the data in a vendor-independent fashion. In the ideal case, both companies will agree upon a standard vocabulary for describing the data using a DTD or schema. The vocabulary is composed of the XML element names used in the XML document. However, in certain cases one of the companies might like to use a different vocabulary. This is where XSL enters the picture. The example in this section describes a B2B scenario between a training company, Hot Shot Training, and a software development company, AcmeSoft. The computer training company maintains a database for the students that have attended its courses. The training company has developed an XML application that produces the list of students for a given class. The management team at AcmeSoft would like to retrieve this list from the training company’s XML application. However, once the data is retrieved, AcmeSoft would like to store the data in a different XML format using its own XML element names. The XML application at the training company is accessible using the HTTP protocol. The first step is to request the XML document from the training company. In step 2, the XML document is retrieved. In step 3, the document is transformed using the supplied XSLT style sheet. Finally, the desired output document is produced in step 4.
  • 65. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 32 <?xml version=”1.0”?> <trainingclass> <title>J2EE Essentials</title> <start_date>24 Sep 2001</start_date> <end_date>28 Sep 2001</end_date> <location>Philadelphia, PA</location> <student> <first_name>Riley</first_name> <last_name>Scott</last_name> <email>riley@acmesoft.web</email> </student> <student> <first_name>Torrance</first_name> <last_name>Lee</last_name> <email>torrance.lee@acmesoft.web</email> </student> </trainingclass> Program: XML document used in Hot Shot Training Company <?xml version=”1.0”?> <employeelist> <course_title>J2EE Essentials</course_title> <course_date start=”24 Sep 2001” end=”28 Sep 2001” /> <location>Philadelphia, PA</location> <employee> <name> <first>Riley</first> <last>Scott</last> </name> <email>riley.scott@acmesoft.web</email>
  • 66. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 33 </employee> <employee> <name> <first>Torrance</first> <last>Lee</last> </name> <email>torrance.lee@acmesoft.web</email> </employee> </employeelist> Program: XML document used in AcmeSoft <?xml version=”1.0”?> <xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0”> <xsl:template match=”/trainingclass”> <employeelist> <course_title><xsl:value-of select=”title” /></course_title> <!-- create attributes for the start and end course dates --> <course_date> <xsl:attribute name=”start”> <xsl:value-of select=”start_date”/> </xsl:attribute> <xsl:attribute name=”end”> <xsl:value-of select=”end_date”/> </xsl:attribute> </course_date> <location><xsl:value-of select=”location” /></location> <!-- Perform a loop for each student in the training class --> <xsl:for-each select=”student” <employee>
  • 67. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 34 <name> <first><xsl:value-of select=”first_name”/></first> <last><xsl:value-of select=”last_name”/></last> </name> <email><xsl:value-of select=”email”/></email> </employee> </xsl:for-each> </employeelist> </xsl:template> </xsl:stylesheet> Program: Stylesheet to transform XML document used in Hot Spot to XML document used in AcmeSoft XSL-FO
  • 68. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 35  XSL-FO elements use the following namespace: http://www.w3.org/1999/XSL/Format  The element <fo:root> is the root element for the XSL-FO document.  An XSL-FO document is divided into two main parts: 1. One layout master set (layout-master-set), which specifies one or more page master templates (simple-page-master) to be used in the document. 2. One or more page sequences, which contain the content of the document. <?xml version="1.0" encoding="utf-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="hello" page-height="11in" page-width="8.5in" margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in"> <fo:region-body margin-top="1in" margin-bottom=".5in"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="hello"> <fo:flow flow-name="xsl-region-body"> <fo:block font-size="18pt" text-align="center" font-weight="bold"> Hello World! </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
  • 69. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 36 Fig: Pagination Tree Structure Page Master Set: <fo:layout-master-set> A document can be composed of multiple pages, each with its own dimensions. The pagemaster set refers to the collection of page masters. Page Master: <fo:simple-page-master> The page master describes the page size and layout. For example, we could use an8.5×11-inch page or an A4 letter. The page master contains the dimensions for a page, including width, height, and margins. Regions The simple-page-master FO contains region settings in the form of the following child FOs.  <fo:region-before>  <fo:region-after>  <fo:region-body>  <fo:region-start>  <fo:region-end>
  • 70. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 37 The region-before and region-after areas are commonly used for page headers andfooters. The region-body area is the center of the page and contains the main content.The region-start and region-end sections are commonly used for left and right sidebars,respectively. Page Sequences: <fo:page-sequence>  A page sequence defines a series of printed pages. Each page sequence refers to a page master for its dimensions. The page sequence contains the actual content for the document.  The <fo:page-sequence> element contains <fo:static-content> and <fo:flow> elements.  The <fo:static-content> element is used for page headers and footers. For example, we can define a header for the company name and page number, and this information will appear on every page.  The <fo:flow>element contains a collection of text blocks. The <fo:flow> element is similar to a collection of paragraphs. A body of text is defined using the <fo:block> element.  The <fo:block> element is a child element of <fo:flow>. The <fo:block> element contains free-flowing text that will wrap to the next line in a document if it overflows. Page Headers and Footers The header is defined using the following code fragment:
  • 71. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 38 <!-- header --> <fo:static-content flow-name=”xsl-region-before”> <fo:block text-align=”end” font-size=”10pt” font-family=”serif” line-height=”14pt” > Ez Books Catalog - page <fo:page-number/> </fo:block> </fo:static-content> The footer is defined using the following code fragment: <!-- footer --> <fo:static-content flow-name=”xsl-region-after”> <fo:block text-align=”center” font-size=”10pt” font-family=”serif” line-height=”14pt” > Visit our website http://www.ezbooks.web </fo:block> </fo:static-content> Graphics XSL-FO also allows for the insertion of external graphic images. The graphic formatssupported are dependent on the XSL-FO formatting engine. The Apache-FOP formatting engine supports the popular graphics formats: GIF, JPEG, and BMP. The following code fragment inserts the image smiley.jpg: <fo:block text-align=”center”> <fo:external-graphic src=”smiley.jpg” width=”200px” height=”200px”/> </fo:block> Tables XSL-FO has rich support for structuring tabular data.
  • 72. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 39 <fo:table> <!-- define column widths --> <fo:table-column column-width=”120pt”/> <fo:table-column column-width=”200pt”/> <fo:table-column column-width=”80pt”/> <fo:table-header> <fo:table-row> <fo:table-cell> <fo:block font-weight=”bold”>Author</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Title</fo:block> </fo:table-cell> <fo:table-cell> <fo:block font-weight=”bold”>Price (USD)</fo:block> </fo:table-cell> </fo:table-row> </fo:table-header> <!-- insert table body and rows here --> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block>Michael Daconta</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>XML Development with Java 2</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>37.99</fo:block> </fo:table-cell>
  • 73. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 40 </fo:table-row> </fo:table-body> </fo:table> Modeling Databases in XML Need for Integrating XML and Database With the emergence of XML as a technique for describing data, the frequently asked question is, “How can we integrate XML with our existing relational database?” In particular, developers need a solution to dynamically generate XML documents using information stored in databases. XML and database integration is important because XML provides a standard technique to describe data. By leveraging XML, a company can convert its existing corporate data into a format that is consumable by its trading partners. XML allows the development team to define a set of custom tags specific to its industry. A trading partner can import the XML data into its system using the given format. The trading partner also has the option of converting the data to a different XML format using XSLT. XML Database Solutions XML Database Mapping The first type of XML database solution provides a mapping between the XML document and the database fields. The system dynamically converts SQL result sets to XML documents. Fig: Mapping XML documents to database fields.
  • 74. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 41 Native XML Support (Native XML database or NXD) The second type of XML database solution actually stores the XML data in the document in its native format. Each product uses its own proprietary serialization technique to store the data. However, when the data is retrieved, it represents an XML document. Fig: Native XML databases. JAXB Solution for Modeling Databases in XML 1. Review the database schema. 2. Construct the desired XML document. 3. Define a schema for the XML document. 4. Create the JAXB binding schema. 5. Generate the JAXB classes based on the schema. 6. Develop a Data Access Object (DAO). 7. Develop a servlet for HTTP access. Fig: The rental property application architecture.
  • 75. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 42 Step 1: Review the database schema Step 2: Construct the desired XML document <rental_property> <prop_id>1</prop_id> <name>The Meadows</name> <address>
  • 76. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 43 <street>251 Eisenhower Blvd</street> <city>Houston</city> <state>TX</state> <postal_code>77033</postal_code> </address> <square_footage>500.0</square_footage> <bedrooms>1.0</bedrooms> <bath>1.0</bath> <price>600</price> <contact> <phone>555-555-1212</phone> <fax>555-555-1414</fax> </contact> </rental_property> Step 3: Define a schema for the XML document <!ELEMENT rental_property_list (rental_property)*> <!ELEMENT rental_property (prop_id, name, address, square_footage, bedrooms, bath, price, contact)> <!ELEMENT prop_id (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT address (street, city, state, postal_code)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT postal_code (#PCDATA)> <!ELEMENT square_footage (#PCDATA)> <!ELEMENT bedrooms (#PCDATA)> <!ELEMENT bath (#PCDATA)> <!ELEMENT price (#PCDATA)>
  • 77. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 44 <!ELEMENT contact (phone, fax)> <!ELEMENT phone (#PCDATA)> <!ELEMENT fax (#PCDATA)> Step 4: Create the JAXB binding schema JAXB 1.0 binding schema files normally use the filename extension .xjs (for XML Java schema). But JAXB 2.0 uses .xjb. JAXB uses a default binding schema that will create properties in the Java class based on the XML element name. But we can customize the default binding schema as follows: Fig: Example JAXB 1.0 Customized Binding Schema (.xjs) <jxb:bindings schemaLocation = "xs:anyURI"> <jxb:bindings node = "xs:string">* <binding declaration> <jxb:bindings> </jxb:bindings> Fig: JAXB 2.0 Customized Binding Schema (.xjb) General Form
  • 78. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 45 Step 5: Generate the JAXB classes based on the schema Using JAXB binding compiler, Java classes are generated from XSD/DTD (One or many bean classes and ObjectFactory class). Fig: Generating Java classes with the JAXB compiler Using JAXB1.0 java com.sun.tools.xjc.Main rental_property.dtd rental_property.xjs -d source_code This command generates source code in the source_code directory. The following files are generated:  RentalPropertyList.java. This file models the <rental_property_list> element.  RentalProperty.java. This file models the <rental_property> element.  Address.java. This file models the <address> subelement.  Contact.java. This file models the <contact> subelement. Step 6: Develop a Data Access Object (DAO) A Data Access Object (DAO) provides access to the backend database. The goal of the DAO design pattern is to provide a higher level of abstraction for database access. The DAO encapsulates the complex JDBC and SQL calls. The DAO provides access to the backend database via public methods. The DAO converts a result set to a collection of objects. The objects model the data stored in the database.
  • 79. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 2 - CSE/RMKCET 46 Fig: Data Access Object design pattern Step 7: Develop a servlet for HTTP access Fig: Servlet and DAO interaction In our solution, we’ll use a servlet to handle the requests to the DAO. In the servlet, we’ll call the appropriate method and return the result as an XML document.
  • 80. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 1 S.No. Name of the Topic Reference Book (Text Book) UNIT III - SERVICE ORIENTED ARCHITECTURE 1. Characteristics of SOA Thomas Erl – Ch: 3.2 2. 3. Comparing SOA with Client-Server Thomas Erl – Ch: 4.3 4. Comparing SOA with Distributed architectures Thomas Erl – Ch: 4.3 5. Benefits of SOA Thomas Erl – Ch: 3.4 6. Principles of Service orientation Thomas Erl – Ch: 8.3 7. 8. Service layers Thomas Erl – Ch: 9.0 9. Contents beyond syllabus CORBA, RMI, IIOP
  • 81. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 2 Need for SOA The Challenges faced by Enterprise Computing before the advent of Service Oriented Architecture (SOA) were:  Scalability  Heterogeneity  Time-to-market  Cost o Development o Operation & Maintenance The issues of Scalability and Heterogeneity were addressed by Component Based Technologies (eg: J2EE – Open, standards based Component & Container model). But the remaining issues of Time-to-market and Cost were not adequately addressed by Component Based Technologies. SOA addresses all of the above mentioned issues. Service Oriented Architecture “Service-oriented architecture” is a term that represents a model in which automation logic is decomposed into smaller, distinct units of logic known as services. This model should adhere to the principles of service-orientation like loose coupling, autonomy, reusability, composability, statelessness, discoverability, abstraction etc. Service It is a unit of processing logic. Collectively, these units comprise a larger piece of business automation logic. Individually, these units can be distributed. Primitive SOA
  • 82. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 3 It is baseline technology architecture, whose core components are services, descriptions, and messages. It supports the basic service oriented principles. What is architecture?  A baseline application that could act as a template for all other applications.  It specifically explains the technology, boundaries, rules, limitations, and design characteristics that apply to all solutions based on this template. Application Architecture  It is a technical blueprint for providing solutions.  An organization can have several application architectures. Enterprise Architecture  It is a master specification providing high-level overview of all forms of heterogeneity that exist within an enterprise. It also contains definition of the supporting architecture.  Any changes to enterprise architecture directly affect application architectures.
  • 83. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 4 Characteristics of SOA Contemporary SOA It extends primitive SOA through application of advanced design techniques and new Web services specifications. Contemporary SOA represents an open, agile, extensible, federated, composable architecture comprised of autonomous, QoS-capable, vendor diverse, interoperable, discoverable, and potentially reusable services, implemented as Web services. Observational Characteristics  Contemporary SOA is at the core of the service-oriented computing platform The term “architecture” refers to any application computing platform. Contemporary SOA represents an architecture that promotes service-orientation through the use of web services.  Contemporary SOA is a building block Organizations standardizing on SOA work toward an ideal known as the service-oriented enterprise (SOE), where all business processes are composed of and exist as services, both logically and physically. In this scenario an individual service-oriented application can, in its entirety, be represented by and modeled as a single service.  Contemporary SOA is an evolution It differs from traditional client-server and distributed environments in that it is heavily influenced by the concepts and principles associated with service-orientation and Web services. It is similar to previous platforms in that it preserves the successful characteristics of its predecessors and builds upon them with distinct design patterns and a new technology set. For example, SOA supports and promotes reuse, as well as the componentization and distribution of application logic.  Contemporary SOA is still maturing Despite the fact that Web services are being used to implement a great deal of application functionality, the support for a number of features necessary for enterprise-level computing is not yet fully available.
  • 84. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 5 When SOA platforms and tools reach an adequate level of maturity, the utilization of Web services can be extended to support the creation of enterprise SOA solutions.  Contemporary SOA is an achievable ideal A standardized enterprise-wide adoption of SOA requires an enormous amount of effort, discipline, and a good amount of time. It is a transition phase now, where various parts of SOA will be phased in at different stages and to varying extents. This will likely result in countless hybrid architectures, consisting mostly of distributed environments that are part legacy and part service-oriented. The advancements in technology set will help in realizing enterprise-level SOAs. Concrete Characteristics  Contemporary SOA increases quality of service Common quality of service requirements: Security: Protecting the contents of a message, as well as access to individual services. Reliability: Guaranteeing message delivery or notification of failed delivery. Performance: Ensuring that the overhead imposed by SOAP message and XML content processing does not inhibit the execution of a task. Transaction: Protecting the integrity of specific business tasks with a guarantee that should the task fail, exception logic is executed. WS-* Extensions provide features that directly address the quality of service requirements.  Contemporary SOA is fundamentally autonomous Services are autonomous. Messages are autonomous. SOA builds upon and expands this principle by promoting the concept of autonomy throughout solution environments and the enterprise.  Contemporary SOA is based on open standards Data exchange is governed by open standards. The message itself is standardized, both in format and in how it represents its payload. The use of SOAP, WSDL, XML, and XML Schema allow for messages to be fully self-contained and support the underlying agreement that to communicate, services require nothing more than knowledge of each other's service descriptions. The use of an open, standardized messaging model
  • 85. IT6801 SERVICE ORIENTED ARCHITECTURE UNIT 3 - CSE/RMKCET 6 eliminates the need for underlying service logic to share type systems and supports the loosely coupled paradigm. An SOA limits the role of proprietary technology to the implementation and hosting of the application logic encapsulated by a service.  Contemporary SOA supports vendor diversity Disparate technology platforms do not prevent service-oriented solutions from interoperating.  Contemporary SOA fosters intrinsic interoperability Intrinsically interoperable services enable unforeseen integration opportunities. Promoting this characteristic can significantly alleviate the cost and effort of fulfilling future cross-application integration requirements.  Contemporary SOA promotes discovery SOA supports and encourages the advertisement and discovery of services throughout the enterprise and beyond. A serious SOA will likely rely on some form of service registry or directory to manage service descriptions. UDDI is the Web services registry standard.  Contemporary SOA promotes federation While Web services enable federation, SOA promotes this cause by establishing and standardizing the ability to encapsulate legacy and non-legacy application logic and by exposing it via a common, open, and standardized communications framework.