Professional Documents
Culture Documents
1
Unit-5: Technologies for SOA
• XML: Namespaces, schemas, processing/passing models
• SOAP: messages, elements, attributes and processing
model, message exchange types ,HTTP binding
• WSDL: containment structure, elements of abstract
description, elements of the implementation part,
logical relationships, SOAP binding
• UDDI Registry: Basic data model, tmodel, categorization
and identification schemes, binding template, use of
WSDL in the UDDI registry
2
XML
• XML is probably the most important pillar of Web
Services.
• a means for passing information between the
service provider and service consumer.
• XML also forms the basis for
– WSDL
– SOAP
– UDDI (Universal Description, Discovery, and
Integration), which is used to publish and discover a
Web Service, is also based on XML.
3
4
XML
• Overview of the XML language.
• Concept of namespaces
• Schemas
• Various models you can use for parsing, processing,
creating, and editing an XML document.
5
XML
• XML uses tags (Similar to HTML).
10
XML contd.
Grammar of an XML document
DTD
XMLSchema
NameSpace is used to
avoid the tag name collisions
extend the use of vocabulary defined in one specific
domain to other
11
Namespaces
XML Namespaces increase reuse across multiple WSDL
documents and across the enterprise and beyond
13
Namespaces
The element's name and the address of the namespace
(http://myCompnny.com/hr/employees) refer to the names and addresses of
the employee' of the company (myCompany).
myCompany's tennis club management also decides to store their member data
in XML format with the element types of name and address.
we can use the prefix to qualify any name of the element.
<myC:address xmlns:myC=“http://myCompany.com/hr/employees”>
<myC:name>John Smith</myC:name>
<myC:street>43 Walcut St</myC:street>
<myC:city>Dublin</myC:city>
<myC:state>Ohio</myC:state>
<myC:postal-code>45561</myC:postal-code>
</myC:address>
15
Namespaces
16
Namespaces
another way to declare and use a namespace without a prefix.
It is called a default namespace. Example
<address xmlns= "http//myCompany.com/hr/employees" >
All subordinate elements are assumed to belong to the default
namespace, provided they are not prefixed
22
XML Schema example
23
XML confirms to Schema
24
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
25
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
26
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
27
XML Processing and Parsing Models
the service provider and service consumer application
exchange data through XML instance documents.
Five choices for XML processing models:
SAX The Simple API for XML is an event-driven parsing
/programming model.
StAX The Streaming API for XML provides a pull, event-
based parsing /programming model.
DOM The Document Object Model provides an in-memory
tree transversal programming model.
XML data-binding Provides an in-memory Java content
class-bound programming model.
XSLT Extensible Stylesheet Language Transformation
provides a template-based programming model. 28
XML Processing and Parsing Models
SAX, DOM more common. StAX catching up.
JAXP APIs (Java APIs for XML Processing) – SAX, DOM, StAX
JAXB technology - XML data binding
The processing includes
Parsing the XML document for processing
Making changes
Creating a new XML document
Deserialization or Unmarshalling Parsing an XML document into an
equivalent data structure
Serialization or Marshalling writing a data structure to an XML
Document
DOM supports both Deserialization and Serialization
SAX supports only Deserialization
29
SAX Processing Model
There are two ways of applying business logic when
using SAX parsing:
First Approach:
The business logic is invoked as soon as the information is
extracted or after minimal aggregation. This approach is
referred to as stream processing
The document can be processed in one step.
Second Approach:
invokes the business logic after complete parsing and
consolidating the extracted information.
Needs two steps to complete the processing of an XML
document.
31
SAX Processing Model
SAX first approach (stream processing) advantage:
it lets an application immediately start processing the content of the
source document.
application does not even have to wait for the entire document to be
retrieved.
Useful when - retrieving document from an earlier processing stage
(pipeline) or from the network
disadvantages :
a document may appear to be well and has unexpected errors at the
end
notices these problems only when it comes across erroneous tokens or
when it cannot resolve an entity reference.
the input stream from which it is reading the document unexpectedly
closes
Use stream processing model within the context of a transaction
32
SAX Processing Model
With the second approach,
parsing the document and applying business logic are
performed in two steps
first ensures that the document and the information
extracted from the document are valid
Once the document data is validated, the application
invokes the business logic
Disadvantages of the SAX model
No facility to modify or produce XML documents.
still possible to generate an XML document by writing
custom serialization handler
33
SAX Processing Model
SAX processing model well suited when
the XML document is very large and needs more memory
Your applications do not make any structural modifications
and no need to generate XML documents.
the document needs only be processed once
you want to implement stream process very large documents
extract and process only part of the XML document
the XML document structure and the order of information
map well to the domain-specific objects
familiar with event-based programming
no need to generate/write XML documents
SAX processing follows a push model
34
SAX Processing Model
35
StAX Processing Model
StAX (Streaming API for XML) is a new API that is becoming
most common processing model for JAVA applications
Like SAX, it is based on streaming
Streaming
a programming model in which XML infosets (sections of XML
document) are transmitted and parsed serially at application
runtime, often in real time, and often from dynamic sources
stream-based parsers can start generating output immediately
infoset elements can be discarded and garbage collected
immediately after they are used.
stream processing provides a smaller memory footprint,
reduced processor requirements
36
StAX Processing Model
Limited to cardboard tube
view of is document
need to know what
processing you want to do
before reading the XML
StAX follows pull streaming
model (a client application
calls methods on an XML
parsing library)
37
StAX Processing Model
Pull model has several advantages over push model:
the client controls the application thread (in pull)
vs the parser controls the application thread
Pull parsing libraries can be much smaller, and the
client code is simpler than with push libraries
Pull clients can read multiple documents at one
time with a single thread.
A StAX pull parser can filter XML documents such
that elements unnecessary to the client can be
ignored
StAX provides marshalling (creating XML docs)
38
StAX Processing Model
Use the StAX processing model when :
You are dealing with very large documents and
memory usage is an issue
You are familiar with event-based programming
The document must be processed only once
There is need for marshalling and unmarshalling
XML documents
You want high performance
39
DOM Processing Model
processing the XML input data involves two
steps:
Advantages:
it is slightly easier to use than the SAX model.
XSLT identity transformation can be used to achieve serialization back to the XML
document
use of XPath with the DOM processing model simplifies many tasks
XPath allows to specify path patterns to locate element content, attribute values, and subtrees,
may eliminate tree-transversal code.
XPath expressions are strings, they can be easily parameterized and externalized in a
41
configuration file
DOM Processing Model
DOM processing model should be used when
The document is not very large and memory usage is not an issue
You want to manipulate an XML document and need fine-grained control over
the document structure that you want to create or edit
You want random access to parts of the document. For example, you want to go
back and forth within the document.
You want to benefit from the flexibility of XPath and apply XPath expressions on
the DOM tree.
You want to implement data binding but you cannot use JAXB technology 42
because the document either has no schema or it conforms to a DTD
XML Data-Binding Processing Model
Allows the processing a XML document without being
concerned with XML representation
The Java Objects created are the instances of the Java classes
generated by the binding compiler using the XSD schema.
44
XML Data-Binding Processing Model
Application can access the source document using Java Bean—style getter and setter
methods.
You can create or edit in-memory content tree and then marshal the tree into an XML
document instance.
Validations can be performed to ensure that the document created satisfies the
constraints expressed in the XSD schema.
Set up the JAXB context (JAXBContext) with the list of derived packages that are used
to unmarshal the document.
Unmarshal an XML document into a content tree. Also, perform validation of the
document
Directly apply the business logic to the content tree or consolidate information from
45
the content tree and then apply business logic on the consolidated information
XML Data-Binding Processing Model
This processing model also supports serialization to XML
want to deal with Java Objects and are not concerned with XML representation
do not need to maintain certain as aspects of an XML document (comments and
entity references)
XSLT complements to these models, and should be used along with these other models
XSLT requires writing of rules and templates that are applied when specified patterns
are encountered in the source document.
The application of the rules adds new fragments or copies fragments from the source
tree to a result tree (XPATH is used to locate and extract information from the source
document)
When using XSLT, one typically writes style sheets, which are themselves XML
documents.
The XSLT API available with JAXP provides an abstract for the source and result of a
transformation, allowing the developer not only the ability to chain transformations but
also to interface with other processing models, such as SAX and DOM. 48
XSLT Processing Model
49
XSLT Processing Model
XSLT should be used when
You want to change the structure or insert, remove, or filter the content of an XML
document.
You want the ability to be flexible and allow future changes in the schemas of
documents you are processing.
You need to minimize performance overhead for large documents that contain a
significant amount of data
You potentially have more than one transformation for the same document—
because of the scripting nature of the style sheets—are better performed using XSLT
transformations 50
52