XML

From Training Material
Jump to navigation Jump to search
title
Web Services Basics For Non-programmers
author
Pete George (NobleProg Ltd)

Day One Schedule ⌘

  1. Introductions
  2. Service-Oriented Architecture
  3. Web Services Overview
  4. XML
  5. SOAP

XML ⌘

Learning Objectives

  • To appreciate the advantages and disadvantages of using XML for Web services
  • To understand the basic structure of an XML message
  • To be aware of Xpath, XSD and XSLT

XML Messaging ⌘

XML 1.png

XML eXtensible Markup Language ⌘

  • W3C Recommendation 1998
  • Most common method for data exchange

eXtensible Markup Language ⌘

XML 2.png

eXtensible Markup Language ⌘

  • Markup language, like HTML

XML 3.png

Why XML and Web Services? ⌘

  • Data not presentation
  • Interoperability
  • Resilience
  • Easily readable

Why XML and Web Services? ⌘

  • Data not presentation

XML 5.png

Why XML and Web Services? ⌘

  • Interoperability

-Easy to agree XML format for data exchange

-High availability of XML parsers

-No need for low-level code to read/write data

XML 4.png

Why XML and Web Services? ⌘

XML is more resilient XML 6.png

Why XML and Web Services? ⌘

  • Easily readable

XML 7.png

Easily Readable? ⌘

XML 10.png

Elements and Attributes ⌘

  • Elements, e.g.

<Users> some users </User>

  • Attributes, e.g.

<user name=“Pete”> User1 </user> or <user name=“Pete”/>

Elements and Attributes ⌘

XML 8.png

Root Element ⌘

  • Well-formed XML has one element at root
<rootElement>
 <anotherElement anAttribute=“some data”>
 </anotherElement>
</rootElement>

Root Element ⌘

XML 9.png

XML Prolog ⌘

  • XML Prolog
<?xml version=“1.0”?>

-Optional, but usually declared

-May contain other information, e.g.

<?xml version=“1.0” encoding=“UTF-8”?>

XML Prolog ⌘

XML 02.png

Namespaces ⌘

  • Group XML elements together
  • Declare namespace

xmlns=<URI>

-E.g. xmlns:PETE=http://pa-uk.net/etc <PETE:users >

Namespaces ⌘

  • URI = Uniform Resource Identifier

-String that points to something

  • Can be:

-URL = Uniform Resource Locator

-Specifies location of a resource

-[scheme]://[Domain]:[Port]/[Path]?[Querystring]#[FragmentId]

-URN = Uniform Resource Name

-Uniquely identifies something

-urn:[namespace identifier]:[namespace specific string]

Namespaces ⌘

XML 03.png

Comments ⌘

  • Comments can also be included

< !--This is a comment-- >

Entity References ⌘

  • Illegal characters can be used by inserting entity references
& = &amp;

< = &lt;

> = &gt;

“ = &quot;

‘ = &apos;

XPath ⌘

  • XML Path Language
  • Query language used to target specific elements or attributes
  • Works like file system paths:
<users>
  <user name=“Pete” />
</users>

XPath = /Users/user

XPath ⌘

XML 11.png

XML Document Definition ⌘

  • Describe structure of XML document
  • Used to test XML document is valid
  • Used to author XML document in editor
  • Document Type Definition (DTD)

-Widespread but on decline

-Not in XML format

XML Schema (XSD) ⌘

  • Defines rules XML document must conform to be considered 'valid’
  • Advantages over DTD:

-In XML format

-Namespace aware

-Data type aware

  • defines elements/attributes containing values such as integers

XSLT ⌘

  • Extensible Stylesheet Language Transformations
  • Transforms XML file into new XML file in new style
  • Can transform XML into other forms, e.g. XHTML

XML Disadvantages ⌘

XML 12.png

Quiz – No Prizes! No Pressure! ⌘

XML 14.png