Unit-3
XML document structure:
An XML document is composed of named containers and their contained data values. Typically,
these containers are represented as declarations, elements, and attributes. A declaration declares
the version of XML used to define the document. The technical term used in XML for a textual
unit, viewed as a structural component, is element. Element containers may be defined to hold
data, other elements, both data and other elements, or nothing at all.
An XML document is also known as an instance or XML document instance. This signifies the
fact that an XML document instance represents one possible set of data for a particular markup
language.
Example of XML Document instance
XML declaration
XML declaration contains details that prepare an XML processor to parse the XML document. It
is optional, but when used, it must appear in the first line of the XML document.
Layout of typical xml Document
Elements
The topmost element of the XML document is a single element known as the root element. The
content of an element can be character data, other nested elements, or a combination of both.
Elements contained in other elements are referred to as nested elements. The containing element
is the parent element and the nested element is called the child element. This is illustrated in
above Figure , where a Purchase Order element is shown to contain a Customer element, which
in turn contains Name and BillingAddress and ShippingAddress elements.
Attributes
Attributes are used to better specify the content of an element on which they appear by adding
information about a defined element. An attribute specification is a name–value pair that is
associated with an element.
XML Namespaces
• A Namespace is a set of unique names. Namespace is a mechanisms by which element
and attribute name can be assigned to a group. The Namespace is identified by
URI(Uniform Resource Identifiers).
Namespace Declaration:
• A Namespace is declared using reserved attributes. Such an attribute name must either
be xmlns or begin with xmlns: shown as below −
<element xmlns:name = "URL">
• The Namespace starts with the keyword xmlns.
• The word name is the Namespace prefix.
• The URL is the Namespace identifier.
• Namespace affects only a limited area in the document. An element containing the
declaration and all of its descendants are in the scope of the Namespace .
• . Following is a simple example of XML Namespace −
<?xml version = "1.0" encoding = "UTF-8"?> <cont:contact xmlns:cont =
"www.mgit.ac.in/profile"> <cont:name>pss varma</cont:name>
<cont:company>mgit</cont:company>
<cont:phone>9666665578</cont:phone>
</cont:contact>
Here, the Namespace prefix is cont, and the Namespace identifier (URI)
as www.mgit.ac.in/profile. This means, the element names and attribute names with
the cont prefix (including the contact element), all belong to
the www.mgit.ac.in/profile namespace.
XML Schemas
• Schemas are themselves XML documents.
• They were standardized after DTDs and provide more information about the document.
• They have a number of data types including string, decimal, integer, boolean, date, and
time.
• They divide elements into simple and complex types.
• They also determine the tree structure and how many children a node may have.
Schema for First address Example
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="phone" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Explanation of Example Schema
<?xml version="1.0" encoding="ISO-8859-1" ?>
• ISO-8859-1, Latin-1, is the same as UTF-8 in the first 128 characters.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
• www.w3.org/2001/XMLSchema contains the schema standards.
<xs:element name="address">
<xs:complexType>
• This states that address is a complex type element.
<xs:sequence>
• This states that the following elements form a sequence and must come in the order
shown.
<xs:element name="name" type="xs:string"/>
• This says that the element, name, must be a string.
<xs:element name="birthday" type="xs:date"/>
• This states that the element, birthday, is a date. Dates are always of the form yyyy-mm-
dd.
The Emergence of SOAP:
SOAP initially was developed by DevelopMentor, Inc., as a platform independent protocol for
accessing services, objects between applications, and servers using HTTP-based communication.
Understanding SOAP Specifications
The SOAP specifications define the following:
■■ Syntax and semantics for representing XML documents as structured SOAP messages
■■ Encoding standards for representing data in SOAP messages
■■ A communication model for exchanging SOAP messages
■■ Bindings for the underlying transport protocols such as SOAP transport
■■ Conventions for sending and receiving messages using RPC and messaging
Note that SOAP is not a programming language or a business application component for building
business applications. SOAP is intended for use as a portable communication protocol to deliver
SOAP messages, which have to be created and processed by an application.In general, SOAP is
simple and extensible by design, but unlike other distributed computing protocols, the following
features are not supported by SOAP:
■■ Garbage collection
■■ Object by reference
■■ Object activation
■■ Message batching