Top Banner
SRM/MCA/HS 1 MC711 XML AND WEB SERVICES L T P C 3 1 2 4 PURPOSE : The purpose of the course is to impart knowledge on eXtensible Markup Language (XML) and to achieve secured, messaging through web services. INSTRUCTIONAL OBJECTIVES: At the end of the course, student should be able to: Write a XML application using structure and presentation technologies Apply XML manipulation technologies such as XSLT, XPath, XLink and XQuery Do Program Manipulation and Dynamic access through DOM architecture Develop web services and ensure security Understand the need of semantic web Role of XML, XML language basics, XML Revolution, XML Technology family, Simple XML fie creation, and XML Namespaces XML document rule, XML structuring, XML presentation technologies, XML Transformation, XSLT, XQUERY, XLINK, XPATH XML Parsers, XML DOM architecture, Classes of DOM family, Combining XML DOM and XSL, Relational Database and XML SOAP protocol, XML-RPC, HTTP, SOAP faults and SOAP attachments, Web services, UDDI, XML security Semantic web Technology, Layered Architecture, RDF and OWL representation TOTAL 45 TEXT BOOK: 1. Frank. P. Coyle - XML, Web Services and the data revolution - Pearson Education, 2002 REFERENCE BOOKS: 1. Gavin Powel - Beginning XML Databases - Wrox Press, 2007 2. Ramesh Nagappan, Robert Skoczylas and Rima Patel Sriganesh, - Developing Java Web Services - Wiley Publishing Inc., 2004 3. Grigoris Antoniou and Frank Van Harmelen,-A Semantic Web Primer - The MIT Press, Cambridge, Massachusetts London, England, 2004 4. Sandeep Chatterjee, James Webber, - Developing Enterprise Web Services -, Pearson Education, 2004 5. McGovern, et al., - Java Web Services Architecture -, Morgan Kaufmann Publishers, 2005
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • SRM/MCA/HS 1

    MC711 XML AND WEB SERVICES L T P C

    3 1 2 4

    PURPOSE :

    The purpose of the course is to impart knowledge on eXtensible Markup Language (XML) and

    to achieve secured, messaging through web services.

    INSTRUCTIONAL OBJECTIVES:

    At the end of the course, student should be able to:

    Write a XML application using structure and presentation technologies

    Apply XML manipulation technologies such as XSLT, XPath, XLink and XQuery

    Do Program Manipulation and Dynamic access through DOM architecture

    Develop web services and ensure security

    Understand the need of semantic web

    Role of XML, XML language basics, XML Revolution, XML Technology family, Simple XML

    fie creation, and XML Namespaces

    XML document rule, XML structuring, XML presentation technologies, XML Transformation,

    XSLT, XQUERY, XLINK, XPATH

    XML Parsers, XML DOM architecture, Classes of DOM family, Combining XML DOM and

    XSL, Relational Database and XML

    SOAP protocol, XML-RPC, HTTP, SOAP faults and SOAP attachments, Web services, UDDI,

    XML security

    Semantic web Technology, Layered Architecture, RDF and OWL representation

    TOTAL 45

    TEXT BOOK:

    1. Frank. P. Coyle - XML, Web Services and the data revolution - Pearson Education, 2002

    REFERENCE BOOKS:

    1. Gavin Powel - Beginning XML Databases - Wrox Press, 2007 2. Ramesh Nagappan, Robert Skoczylas and Rima Patel Sriganesh, - Developing Java Web

    Services - Wiley Publishing Inc., 2004

    3. Grigoris Antoniou and Frank Van Harmelen,-A Semantic Web Primer - The MIT Press, Cambridge, Massachusetts London, England, 2004

    4. Sandeep Chatterjee, James Webber, - Developing Enterprise Web Services -, Pearson Education, 2004

    5. McGovern, et al., - Java Web Services Architecture -, Morgan Kaufmann Publishers, 2005

  • SRM/MCA/HS 2

    MC0711 XML Web Services

    S.N. Exercise Date of Completion

    1-4. Simple XML file creation

    5. Empty element

    6. Root element

    7. Child elements

    8. XMLDOC Extensible

    9. Attributes

    10. Attribute to element conversion

    11. Attribute as meta data

    12. Including all options

    13,14 Special Markup elements

    15. Comment to exclude the document

    16. Use firstobject editor, MSWord, MSExcel

    17. XML and CSS Example for PI

    18. Internal DTD implementation

    19. External DTD implementation

    20. DTD with CDATA

    21. CDATA usage

    22. XML schema

    23. XML schema creation in .Net*

    24. HTML file to validate schema based XML

    25. XML- Schema validation Additional exercise

    26. Step by step Schema Development Example

    27. CSS Presentation

    28. XSL formatting

    29. XSLTransformation with various options

    30. XSLT for-each sort element

    31. XSLT if and choose, when element

    32. XPATH implementation

    33. Data in Tabular form

    34. Implement XLINK*

    35. XML DOM elements

    36. XML ParseError elements

    37. DOM Object Properties

    38. Parse XMLDocument using XMLDOM

    39. XML data access in .Net*

    40. Web Services : .Net, Java*

    * Demo Only

    Staff Signature

  • SRM/MCA/HS 3

    Unit I: Role of XML, XML language basics, XML Revolution, XML Technology family,

    Simple XML fie creation, and XML Namespaces

    1. Introduction:

    The Need of XML: There are three major aspects to extending the enterprise from a relatively

    constrained network to the broad reach of the Web. The most commonly considered aspect is the

    business-to-consumer (B2C) connection, exploiting opportunities that abound in online

    commerce. Another area is the business-to-employee (B2E) connection, adding efficiencies in

    operations and customer contact by using the Web instead of proprietary networks. A third area,

    and one of particular interest to businesses trying to survive in competitive environments, is the

    business-to-business (B2B) connection made possible by the Web. Together, these opportunities

    are driving what is seen as the extended enterprise, a mix of traditional networks and the loose

    space of the Web.

    2. History of Markup Languages

    Markup is a method of conveying metadata (information about another dataset).

    GML (General Markup Language)

    SGML (Standard Generalized Markup Language) SGML-based markup languages all use literal

    strings of characters, called tags to delimit the major components of the metadata, called

    elements

    HTML (part of sgml for internet) - deals presentation of data . pioneered by tim-lee

    But no reusability of data ie) data retrieval not possible Few tags of HTML are not having end

    tags

    XML (root from SGML) . only for representation of data . structuring

    For browser side no better technology than HTML

  • SRM/MCA/HS 4

    The issues with HTML

    Merits: Shortcomings:

    Very easy to use & learn

    Presentation technology

    It is the most popular

    NOT a data technology

    Poor Searching

    There is no Intelligence of content/data

    We loose meaning association with content

    Data cannot be represented hierarchically

    Limited set of tags

    XML Vs HTML

    Similar in appearance

    Both are based on SGML

    BUT

    XML describes data (XML was designed to transport and store data, with focus on what data is )

    HTML displays data (HTML was designed to display data, with focus on how data looks )

    The W3C developed ten design goals for XML, to quote from the Recommendation: The design

    goals for XML are:

    i. XML shall be straightforwardly usable over the Internet. ii. XML shall support a wide variety of applications.

    iii. XML shall be compatible with SGML. iv. It shall be easy to write programs that process XML documents. v. The number of optional features in XML is to be kept to the absolute minimum,

    ideally zero.

    vi. XML documents should be human-legible and reasonably clear. vii. The XML design should be prepared quickly.

    viii. The design of XML shall be formal and concise. ix. XML documents shall be easy to create. x. Terseness in XML markup is of minimal importance.

    3.What is XML ?

    XML stands for EXtensible Markup Language

    XML is a markup language much like HTML

    XML was designed to carry data, not to display data

    XML tags are not predefined. You must define your own tags

    XML is designed to be self-descriptive

    XML is a W3C Recommendation

  • SRM/MCA/HS 5

    XML (eXtensible Markup Language) provides a standards-based method for describing data.

    XML)is a simple data description language with profound implications. XML has the ability to

    describe data using a simple grammar that is highly interoperable among the many

    heterogeneous systems that are connected to the Internet. XML has a several key strengths that

    have helped it to become the de facto method for describing data:

    XML is a text-based language, which makes it easily readable and more portable than binary data format

    XML give the ability to define your own tags to describe data and its relationships to other data

    XML strictly enforces its language syntax, unlike HTML.

    Parsers are widely available to accurately parse and validate XML structure that you define, which means you dont have to do it yourself.

    It is a meta language defined by w3C and it is open standards. XML is a set of rules and

    guidelines for describing structured data in plain text. It can be read by any existing

    language/tools which makes xml is a common message communication over SOAP protocol for

    exchanging data. All the tags in XML are user defined tags.

    All XML file should have

    (i) processing instructions (ii) all tags should have end tag and properly nested (iii) all xml should have root element (iv) case sensitive

    The rules of XML is checked by parser. (parser does not change format of file, only checks but compiler checks the syntax and change the file into another format)

    well formed xml file is parsed and valid by parser.

    XML is a o platform-independent, o self-describing, o expandable, o standard data exchange format o that can be used either independently or o embedded and used within other solutions. o Describes the information, not the presentation. Format flexible. o Derived as a subset of SGML o Allows you to define your own tags : Example: Dec 06, 2006 o XML: YAG (own Tags) o HTML: YAG (Predefined tags) o Provides meaningful & readable data o Meaning searches can be performed o Much simpler than SGML, SGML spec = 300 pages, XML = 33 pages o Purely a Data Technology o Supports compound documents

  • SRM/MCA/HS 6

    XML Separates Data from HTML: With XML, data can be stored in separate XML files. This

    way you can concentrate on using HTML for layout and display, and be sure that changes in the

    underlying data will not require any changes to the HTML.

    XML Simplifies Data Sharing: In the real world, computer systems and databases contain data in

    incompatible formats. XML data is stored in plain text format. This provides a software- and

    hardware-independent way of storing data. This makes it much easier to create data that can be

    shared by different applications.

    XML Simplifies Data Transport: One of the most time-consuming challenges for developers is to

    exchange data between incompatible systems over the Internet. Exchanging data as XML greatly

    reduces this complexity, since the data can be read by different incompatible applications.

    XML Simplifies Platform Changes: Upgrading to new systems (hardware or software platforms),

    is always time consuming. Large amounts of data must be converted and incompatible data is

    often lost. XML data is stored in text format. This makes it easier to expand or upgrade to new

    operating systems, new applications, or new browsers, without losing data

    XML Makes Your Data More Available: Different applications can access your data, not only in

    HTML pages, but also from XML data sources. With XML, your data can be available to all

    kinds of "reading machines" (Handheld computers, voice machines, news feeds, etc), and make it

    more available for blind people, or people with other disabilities.

    XML advantages:

    Web based Extensible License-free Platform independent Single end-to-end IT solution for electronic information exchanges Lower cost than EDI Easy to interpret Domain specific vocabulary Data interchange between different system

    XML has had an impact across a broad range of areas. The following is a list of some of the

    factors that have influenced XML's adoption by a variety of organizations and individuals.

    XML files are human-readable. XML was designed as text so that, in the worst case,

    someone can always read it to figure out the content. Such is not the case with binary data

    formats.

    Widespread industry support exists for XML. Numerous tools and utilities are being

    provided with Web browsers, databases, and operating systems, making it easier and less

    expensive for small and medium-sized organizations to import and export data in XML

    format.

    Major relational databases now have the native capability to read and generate XML data.

  • SRM/MCA/HS 7

    A large family of XML support technologies is available for the interpretation and

    transformation of XML data for Web page display and report generations.

    XML integrates with standard Web protocols such as HTTP and FTP.

    4.Role of XML:

    XML is a specification for defining new markup languages. XML is a meta-language (literally a

    language about languages) defined by the World Wide Web Consortium (W3C), one of the main

    organizations driving the push to open Web standards. In its simplest sense, XML is a set of

    rules and guidelines for describing structured data in plain text rather than proprietary binary

    representations. However, as a phenomenon, XML goes beyond its technical specification. Since

    its standardization by the W3C in 1998, XML has been the driving force behind numerous other

  • SRM/MCA/HS 8

    standards and vocabularies that are forging a fundamental change in the software world. XML

    has enabled industry vocabularies and protocols.

    5.XML Language Basics

    XML is simple. Technically, it's a language for creating other languages based on the insertion of

    tags to help describe data. However, XML is actually more than just tags.

    XML is a combination of tags and content in which the tags add meaning to the content. The

    following is a simple XML markup of customer information. Start tags such as begin an

    element that contains the actual data. End tags such as mark the end of an element

    definition.

    John von Neumann

    914.631.7722

    914.631.7723

    [email protected]

    For a company like ZwiftBooks, deciding on an XML representation for their data is a first step.

    In trying to come up with an XML data vocabulary that may be useful in automating operations,

    it's helpful to examine use cases that describe what occurs during a business interaction. Figure

    2.2 illustrates the essence of a ZwiftBooks customer request and response.

  • SRM/MCA/HS 9

    XML elements:

    XML Attributes:

  • SRM/MCA/HS 10

    Exercise 1: Create a Simple XML file:

    Fundamental XML

    Surya

    Intro

    Java for Beginners

    Sathya

    Beginner

    The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (is

    utf-8 character set). The next line describes the root element of the document . The next

    lines describe the child elements , ,

    Exercise 2:

    Open a notepad and type the information and view it in a browser:

    XML Design Principle:

    There are three key design elements that by omission contribute to XML's success:

    No display is assumed. Unlike HTML, XML makes no assumptions about how tags will be rendered in a browser or other display device. Auxiliary technologies such as style

    sheets add this capability.

  • SRM/MCA/HS 11

    There is no built-in data typing. DTDs and XML Schema provide support for defining the structure and data types associated with an XML document.

    No transport is assumed. The XML specification makes no as sumption about how XML is to be transported across the Internet. This has opened the door to creative ideas about

    delivering XML by means of HTTP, FTP, or Simple Mail Transfer Protocol (SMTP).

    6.XML Revolution

    The three revolutions: data, architecture, and software. the three areas of impact are data, which

    XML frees from the confines of fixed, program-dependent formats; architecture, with a change

    in emphasis from tightly coupled distributed systems to a more loosely coupled confederation

    based on the Web; and software, with the realization that software evolution is a better path to

    managing complexity than building monolithic applications

    a) The Data Revolution

    Data is now free to travel the Web. Prior to XML, data was very much proprietary, closely

    associated with applications that understood how data was formatted and how to process it. Now,

    XML-based industry-specific data vocabularies provide alternatives to specialized Electronic

    Data Interchange (EDI) solutions by facilitating B2B data exchange and playing a key role as a

  • SRM/MCA/HS 12

    messaging infrastructure for distributed computing. XML enables the creation of program-

    independent data formats.

    XML's strength is its data independence. XML is pure data description, not tied to any

    programming language, operating system, or transport protocol. In the grand scheme of

    distributed computing this is a radical idea. The implication is that we don't require lock-in to

    programmatic infrastructures to make data available to Web-connected platforms. In effect, data

    is free to move about globally without the constraints imposed by tightly coupled transport-

    dependent architectures. XML's sole focus on data means that a variety of transport technologies

    may be used to move XML across the Web. As a result, protocols such as HTTP have had a

    tremendous impact on XML's viability and have opened the door to alternatives to CORBA,

    RMI, and DCOM, which don't work over TCP/IP. XML does this by focusing on data and

    leaving other issues to supporting technologies.

    The Code, Data, Document Culture:

    XML has emerged from a document culture. To understand XML's impact on the computing

    world, it's useful to place XML in perspective. As Figure 1.9 shows, XML comes out of a

    document culture that is distinct from the code and data cultures that are the hallmarks of the

    mainstream computer industry. The code culture is characterized by a focus on programming

    languages, beginning with FORTRAN and evolving through Algol to C, C++, and Java. The data

    culture is characterized by COBOL, data processing, and databases. Both the data and code

    cultures carry with them a built-in propensity to view the world through either a code or a data

    lens. From a code perspective, data is something to be transported by procedure calls. From a

    data perspective, data is something to be stored in databases and manipulated

    Code and data have defined systems thinking. The late 1980s and early 1990s saw code and data

    combine in the form of object-oriented languages such as C++, Smalltalk, Java, and Object

  • SRM/MCA/HS 13

    COBOL. And yet, object technology was only a partial answer. As practitioners in the data world

    had long realized, transactionsthe ability to update multiple databases in an all-or-none mannerare essential to serious industrial-strength enterprise applications. Because component frameworks provide transactions as a service to applications regardless of language origins, the

    playing field quickly shifted from objects to components. Thus infrastructures such as CORBA,

    DCOM, and Enterprise JavaBeans (EJB) provide interconnection, security, and transaction-based

    services for extending the enterprise. In the mid 1990s, components were the only way to extend

    legacy. However, XML changed the rules of the game.

    XML opens up options for treating code as data. XML's emergence from the data-oriented

    document culture has forced a rethinking about application development, particularly for those

    accustomed to thinking of building applications from a code-based perspective. What XML

    brings to the computing world is a technology that allows data to be freed from the constraints

    created by code-centric infrastructures. Instead of requiring data to be subordinated to parameters

    in a procedure call, XML now permits data to stand on its own. More radically, it allows code to

    be treated as data, which has been the driving force behind using XML for remote procedure

    calls. As Figure 1.10 illustrates, XML offers an alternative to both EDI and technologies such as

    CORBA, RMI, and DCOM that lock data transfer into underlying networks and object

    infrastructures. It is this change in perspective that is driving the widespread use of XML across

    the entire computing industry and opening up new patterns of interaction, including Web

    services.

    b) The Architectural Revolution

    Simplicity and the ability to combine different standards are driving forces behind W3C

    deliberations . Together these XML-based technology initiatives open up new possibilities for

    distributed computing that leverage the existing infrastructure of the Web and create a transition

    from object-based distributed systems to architectures based on Web services that can be

  • SRM/MCA/HS 14

    discovered, accessed, and assembled using open Web technologies. The focal point of this

    change in architectural thinking has been a move from tightly coupled systems based on

    established infrastructures such as CORBA, RMI, and DCOM, each with their own transport

    protocol, to loosely coupled systems riding atop standard Web protocols such as TCP/IP.

    Although the transport protocols underlying CORBA, RMI, and DCOM provide for efficient

    communication between nodes, their drawback is their inability to communicate with other

    tightly coupled systems or directly with the Web.

    XML and the Web have enabled the loose coupling of software components. Loosely coupled

    Web-based systems, on the other hand, provide what has long been considered the Holy Grail of

    computing: universal connectivity. Using TCP/IP as the transport, systems can establish

    connections with each other using common open-Web protocols. Although it is possible to build

    software bridges linking tightly coupled systems with each other and the Web, such efforts are

    not trivial and add another layer of complexity on top of an already complex infrastructure. As

    Figure 1.11 shows, the loose coupling of the Web makes possible new system architectures built

    around message-based middleware or less structured peer-to-peer interaction.

    c) The Software Revolution

    XML is part of a software revolution centered around combination and surprise. XML is also

    part of a revolution in how we build software. During the 1970s and 1980s, software was

    constructed as monolithic applications built to solve specific problems. The problem with large

    software projects is that, by trying to tackle multiple problems at once, the software is often ill-

    suited to adding new functionality and adapting to technological change. In the 1990s a different

    model for software emerged based on the concept of simplicity. As Figure 1.12 illustrates,

    instead of trying to define all requirements up front, this new philosophy was built around the

    concept of creating building blocks capable of combination with other building blocks that either

    already existed or were yet to be created.

  • SRM/MCA/HS 15

    The Web is an example of the power of combination. Figure 1.13 illustrates how the Web as we

    know it was not something thought out in strict detail. Each of the contributing technologies

    focused on doing one thing well without inhibiting interconnection with other technologies. The

    essential idea was to maximize the possibility of interaction and watch systems grow. The result

    is the Web, a product of the confluence of forces that include the Internet, HTML, and HTTP.

    Let's now look at how these same forces of combination and collaboration are driving the

    revolution in software.

    The power of combination is finding its way not only into software construction but up the

    development chain to software specification and design. Rather than hoping to meet the needs of

    users, design is now more collaborative, bringing in stakeholders early to ensure maximum

    feedback and the benefits of collaborative thinking. Figure 1.14 illustrates how this collaborative

    model is used by the W3C, the Internet Engineering Task Force, and Sun in its Java Community

  • SRM/MCA/HS 16

    Process.

    7.XML Technology Family

    XML derives its strength from a variety of supporting technologies. XML is not just a

    technology for defining data vocabularies. Surrounding XML is a wide variety of XML

    standards and initiatives that act in combination with XML to address many of the issues

    associated with bringing XML into mainstream computing, namely presentation, structure, and

    transformation. As Figure 2.1 shows, the XML core includes XML itself, based on the XML 1.0

    specification, and namespaces, the specification that allows XML documents from different

    sources to be combined and yet be able to disambiguate elements with the same name from

    different sources. Following is a list of other categories in the XML technology:

    Structure and data types: When using XML to exchange data among clients, partners, and

    suppliers, it's important to be able to define how XML documents should be structured.

    DTDs and XML Schema provide this capability. DTDs come out of the world of

    Standard Generalized Markup Language (SGML), focusing primarily on structure by

  • SRM/MCA/HS 17

    specifying what elements and attributes are considered valid for a particular XML

    instance document. DTDs have limited capability to specify data types, a circumstance

    that can be explained historically by considering their origins in the document culture

    (see Figure 1.9 in Chapter 1). XML Schema is a more recent initiative of the World Wide

    Web Consortium (W3C) that puts a more conventional data processing spin on describing

    XML data with more precision than with DTDs.

    XML presentation technologies: In keeping with an important design pattern for robust

    systems, XML intentionally separates data content from presentation through the

    introduction of supporting technologies that focus on delivering content to users via a

    variety of devices and presentation media. Among the technologies for presentation are

    XHTML, a modular XML-conformant replacement for HTML; CSS for controlling the

    display properties of HTML or XML in Web browsers; XSL and XSL Formatting

    Objects (XSL-FO) for formatting XML for various output media; XForms for collecting

    data from Web forms and returning XML; VoiceXML, for delivering content to voice-

    enabled devices; and Wireless Markup Language (WML), for delivery to wireless

    devices enabled for Wireless Application Protocol (WAP).

    XML manipulation technologies: Manipulation technologies provide the capability to

    extract and transform XML in different ways. These technologies play an important role

    in server-based XML processing for business-to-business (B2B) data manipulation and

    exchange. XSLT is widely used to transform XML from one format to another; XPath is

    a technology used by other XML technologies to navigate through an XML tree structure

    and zero in on particular elements or subtrees; XLink is a technology for creating and

    describing links between resources and for enabling links that go beyond the simple

    unidirectional links of the current Web; and XQuery is an evolving technology for

    extracting and querying XML repositories.

    Other related technologies: The XML family of technologies also includes initiatives for

    working with metainformation, which is literally information about the information

    contained in an XML document. Technologies in this space include RDF and InfoSet.

  • SRM/MCA/HS 18

    The core of XML and its key components and extensions are:

    XML 1.0 syntax, including Document Type Definitions (DTDs)

    Namespaces in XML

    XML Schema (or one of its alternatives or supplemental validation tools: XDR, SOX, RELAX, TREX, and The Schematron)

    Some of the key features that are commonly required in XML applications.

    Describing XML data structure: The XML Information Set (XML Infoset) and XML Path Language (XPath)

    Navigating & Linking: XML Linking (XLink), XML Pointer Language (XPointer), XML Inclusions (XInclude), XML Fragment Interchange (XFI), and XML Query

    Language (XQuery).

    Transforming & Presenting: XSLT and XSL-FO (XSL Formatting Objects)

    8.XML Namespaces:

    Namespaces eliminates the ambiguity of the same name from different providers.

    When developing xml documents, it is common to refer to element and attribute names that share

    a common context as vocabulary. The possibility arises that an element or attribute in that

    vocabulary may have a name that is identical to an element or attribute used by someone else in a

    different vocabulary.

    XML namespaces is a simple technology solution that allows element and attribute names to be

    distinguished from the similarly named elements and attributes of other XML users. XML

    namespace solve this ambiguity problem by associating explicit namespace (or vocabulary) with

    elements and attributes in XML document. Thus a namespace is essentially a set of names in

    which all the elements and attribute names can be guaranteed to be unique.

    Figure 2.3 illustrates how a namespace may be used to disambiguate duplicate element names.

    XML namespaces solves the problem of clashing names by providing for a unique prefix to be

    attached to the beginning of element and attribute names. In practice, a company's Web address

    is often used as the unique prefix, but technically the namespaces specification allows any

    Uniform Resource Identifier (URI) to be used. URIs are more general than the common Uniform

    Resource Locator (URL) and include just about any unique name one wants to use. The usual

    result, though, is that when namespaces are used in an XML document, the official element name

    is actually a two-part name: the name of the XML namespace plus the name of the element or

    attribute.

  • SRM/MCA/HS 19

    Namespace Declarations

    There are several ways to add a namespace to an XML document so that, when software is

    processing XML data from ZwiftBooks, it will see ZwiftBooks elements as

    http://www.zwiftbooks.com:title instead of just title. The simplest approach is to declare a

    namespace in a top-level element and let all the elements and attributes under the top element

    come under the scope of the namespace. For example, the following XML document adds a

    ZwiftBooks namespace to an XML book description document.

    0-596-00058-8

    XML in a Nutshell

    Harold, Elliotte Rusty

    In this example, the namespace declaration is applied to the book element by adding the

    predefined attribute xmlns and giving as its value the unique URL of ZwiftBooks,

    http://www.zwiftbooks.com. Because the xmlns attribute appears in the book element, all

    subelements (isbn, title, and author) are included in the namespace.

    Example 2:

    This XML document carries information in a table:

    Apples

    Bananas

  • SRM/MCA/HS 20

    This XML document carries information about a table (a piece of furniture):

    African Coffee Table

    80

    120

    If these two XML documents were added together, there would be an element name conflict

    because both documents contain a element with different content and definition.

    Using Namespace to avoid conflict:

    This XML document carries information in a table:

    Apples

    Bananas

    This XML document carries information about a piece of furniture:

    African Coffee Table

    80

    120

    Instead of using only prefixes, we have added an xmlns attribute to the tag to give the

    prefix a qualified name associated with a namespace.

    Figure 2.4 illustrates the use of multiple namespaces within the same document and how

    namespaces are useful in distinguishing which elements are which. In this example, the top-level

    element, supercatalog, is in its own namespace. Its two book subelements, technically within

    the scope of the supercatalog namespace declaration, define their own namespaces, so that we

    end up with three namespaces within the XML.

  • SRM/MCA/HS 21

    Namespace Abbreviations

    Namespace abbreviations may be used to simplify writing and reading the XML. The

    namespaces specification also makes it possible to use abbreviations for namespaces in order to

    make XML documents more readable. Figure 2.5 shows how we can define a shortcut name,

    zbooks, so that anywhere that zbooks appears in a document, a software program processing the

    document will replace it with the actual namespace, http://www.zwiftbooks.com.

  • SRM/MCA/HS 22

    9. XML Vs EDI

    EDI or Electronic Data Interchange is the exchange of information in a standard format between

    computers without any human intermediary

    It's difficult to define XML (eXtensible Markup Language) in one sentence because of its dual

    function as a scripting language and a file format.

    Both EDI and XML formats are structured to describe the data they contain. The main

    difference would be that the EDI structure has a record-field-like layout of data segments and

    elements, which makes the EDI file shorter, but not easily understandable; while the XML

    format has tags, which is more easily understood, but making the file bigger and verbose.

    EDI XML

    Need defined rules Need defined rules

    Structure is implicit Structure is explicit

    Machine to Machine interaction Both Machine to Machine and Machine to

    Human interaction

    Widely used in large industries Widely used in large industries

    Expensive for SMEs Cost effective for SMEs

    Conversion capable for WWW WWW enabled