Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.

Similar presentations


Presentation on theme: "1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University."— Presentation transcript:

1 1 © Netskills Quality Internet Training, University of Newcastle Introducing XML http://www.netskills.ac.uk/ © Netskills, Quality Internet Training University of Newcastle Netskills is a trademark of Netskills, University of Newcastle.

2 2 © Netskills Quality Internet Training, University of Newcastle Topics What is XML? Mark-up languages SGML, HTML and XML Advantages of XML over SGML & HTML Structuring data with XML Creating well formed XML documents Tags, Elements and Attributes XML declaration Document Type Definition (DTD) Namespaces Displaying XML documents

3 3 © Netskills Quality Internet Training, University of Newcastle What is XML eXtensible Markup Language Very powerful internet technology The core of a suite of technologies used for management, display and exchange of data Associated technologies include: XSL – eXtensible Style Language XPath - language for addressing parts of an XML document DOM – standardised Document Object Model

4 4 © Netskills Quality Internet Training, University of Newcastle Mark-up Languages Originally developed for printing electronic documents Mark-up tags to allow processing software to determine the formatting, structure or meaning of marked up data Most have been developed from SGML Standard Generalised Mark-up Language ISO standard since 1986 Complex, rigid but widely used meta-language Unsuited to data interchange on the internet

5 5 © Netskills Quality Internet Training, University of Newcastle HTML and XML HTML (Hyper Text Mark-up Language) Only intended for displaying documents in an HTML browser Originally created using SGML for web delivery Finite, predetermined set of tags Limited information about what the data represents Several different versions of the language XML (eXtensible Mark-up Language) A simplified version (subset) of SGML for users to create their own mark-up language Therefore it is not a new version of HTML but a different concept

6 6 © Netskills Quality Internet Training, University of Newcastle XHTML This is the new version of HTML W3C Recommendation since Jan 2000 XML was designed to describe data and HTML was designed to structure data for display XHTML combines strengths of both XHTML documents are HTML web pages that can also be treated as XML documents Can be read by all XML enabled devices Should work in all HTML browsers By using XHTML you prepare for future browser and software development www.w3schools.com/xhtml www.w3.org/MarkUp

7 7 © Netskills Quality Internet Training, University of Newcastle Advantages of XML Developers can create their own tags Complete flexibility to structure data in any way for any application Self-describing language e.g. Joe Bloggs Separates the data content from presentation XML document contains no information on how the data is to be displayed Display handled by separate style sheets XML provides a mechanism for structuring and describing data

8 8 © Netskills Quality Internet Training, University of Newcastle Structuring Data with XML Hierarchical structure Relationships between data items called elements Two main relationships parent/child is a parent of "William" is a child of sibling/sibling and are siblings Structure often referred to as the document tree Macbeth William Shakespeare

9 9 © Netskills Quality Internet Training, University of Newcastle Tags and Elements Macbeth William Shakespeare Christine Stephen King One document or root element Opening & Closing tags (case sensitive) Element Tags must be nested correctly (cannot overlap) White space is preserved in text

10 10 © Netskills Quality Internet Training, University of Newcastle Using Attributes Attributes are simple name/value pairs associated with an element Macbeth William Shakespeare Elements can have more than one attribute Use of attributes is mainly a matter of preference and purpose Attribute Value - matching " or ' quotes Name

11 11 © Netskills Quality Internet Training, University of Newcastle XML Declaration Identifies the document to the XML processor (parser) Must be at the beginning of the document Macbeth William Shakespeare XML declaration is optional, but should be included as a matter of good practice

12 12 © Netskills Quality Internet Training, University of Newcastle Further Details Comments Empty elements All elements must have a start and end tag Empty elements can be represented by

13 13 © Netskills Quality Internet Training, University of Newcastle Well-formed or Valid? A well-formed document A document that complies to the basic structure required by the XML standard is a well-formed document All XML documents must be well-formed They will not work otherwise! A valid document A well-formed document that also conforms to structuring rules defined in an associated DTD or XML Schema Valid documents are crucial for ensuring consistent and reliable data exchange

14 14 © Netskills Quality Internet Training, University of Newcastle DTD and Schema DTD (Document Type Definition) SGML mechanism for specifying rules for structure and content of marked up documents Elements, Data, Attributes, Default values etc. DTD is part of the XML 1.0 specification - very widely used Any XML document can be validated against a DTD to ensure that it obeys the rules DTD not written using XML and once created are inflexible XML Schema Re-formulation of the principles of DTD for XML "A DTD written in XML" Schemas are also XML documents Flexible and extendible Multiple schemas per document Becoming more widely used as tools become available

15 15 © Netskills Quality Internet Training, University of Newcastle XML Namespaces Mechanism to identify subsets of XML elements Can be used as a unique reference to identify subsets and consider them in context e.g. Documents using the same element names for different purposes Dr Macbeth Large documents with sets of elements to be used by different processes Two types of namespace declaration URL is used to provide unique reference Default namespaces xmlns="http:www.netskills.ac.uk/NS/books-ns" Prefixed namespaces xmlns:books="http:www.netskills.ac.uk/NS/books-ns"

16 16 © Netskills Quality Internet Training, University of Newcastle Namespace Syntax people.xml DR John Smith books.xml Christine Stephen King loans.xml <loans xmlns:person="http://www.netskills.ac.uk/NS/person-ns" xmlns:item="http://www.netskills.ac.uk/NS/books-ns"> DR John Smith Christine Stephen King Context given by prefixes Namespace is declared using the xmlns attribute of the root element. A prefix is used. All elements that use the prefix belong in this namespace

17 17 © Netskills Quality Internet Training, University of Newcastle DR John Smith Christine Stephen King Default Namespaces Namespace is declared using the xmlns attribute of the element. No prefix is used so all the children of now belong in this namespace A different default namespace is applied here to all of the elements within the element

18 18 © Netskills Quality Internet Training, University of Newcastle Displaying XML Documents An XML document contains no information about how to display the data it describes Style sheets are used to apply display formatting to an XML document Cascading Style Sheets (CSS) Also used with HTML Extensible Style Sheet Language (XSL) Specifically designed for XML

19 19 © Netskills Quality Internet Training, University of Newcastle Using Style Sheets Document - books.xml <?xml-stylesheet type="text/css"  href="bookstyle.css"?> Macbeth William Shakespeare Style Sheet - bookstyle.css booklist {background-color:yellow} book {display:block;} title {font-size:24pt;} author {font-size:20pt;} firstname {display:none;} lastname {color:blue;} Documents delivered to the client which applies formatting XML processing instruction to call a style sheet

20 20 © Netskills Quality Internet Training, University of Newcastle Summary XML is a very powerful internet technology Allows authors to create their own markup tags and determine the formatting, structure or meaning of data XML documents must be well formed Rules for structure and content of valid XML documents are specified in a DTD or Schema XML namespaces are used to give context to elements of the same name used for different purposes XML separates data content from presentation Presentation of data is handled by style sheets


Download ppt "1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University."

Similar presentations


Ads by Google