Download presentation
Presentation is loading. Please wait.
Published byArthur Chandler Modified over 9 years ago
2
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University of the West Indies, Cave Hill Campus Barbados The Department of Computer Science Mathematics and Physics, University of the West Indies, Cave Hill Campus, Barbados © 2007 Dr. Paul Walcott
3
Session Objectives After completing this session you will be able to: Compare and contrast the two main types of XML parsers Create an XML document
4
XML Extensible Markup Language (or XML) is another markup language XML is a subset of SGML (Standard Generalised Markup Language) SGML is a meta language used to create other languages, e.g. XML and HTML The purpose of XML is different from HTML
5
XML describe data in a structured way and is used to define other markup languages XML allows the creation of custom tags (unlike HTML whose tags are predefined) XML uses a DTD to describe the data Several XML standards have been defined, for example to markup mathematical formula, and chemical molecular structures XML Cont’d
6
The main difference between XML and HTML are: 1 XML was designed to carry data HTML is about displaying information, while XML is about describing information XML is not a replacement for HTML XML Cont’d
7
XML and HTML were designed with different goals: XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. XML Cont’d
8
XML Document Structure 2 XML documents are typically stored in text files with a.xml extension An XML document contains one root element, which contains all other elements The lines preceding the root element are the prolog of the XML document Nested elements are called child elements
9
An XML parser is required to process an XML document The XML parser Checks the document’s syntax Reports any errors Allows access to the contents of the document through program control XML Document Structure Cont’d
10
An XML document is well formed if It has one root element It has a start and end tag for each element Except in the case of empty tags that have a special notation that allows the representation of a start and end tag in a single tag The tags are properly nested E.g. 100 is a cross tag while 100 is properly nested
11
XML Document Structure Cont’d Attribute values are in quotation marks, either single or double Elements and attributes are correctly capitalised since XML is case sensitive
12
XML Document Structure Cont’d XML documents typically contain Carriage returns, Linefeeds Elements and attributes Unicode characters XML elements define structure XML attributes describe elements
13
XML Document Structure Cont’d An element may have zero or more attributes Attributes are placed within the start tag Attribute values are enclosed in single or double quotes
14
XML Document Structure Cont’d Element and attribute names: May be of any length May contain letters, digits, underscores, hyphens and periods Must begin with a letter or underscore Spaces are not allowed in element or attribute names
15
XML Document Structure Cont’d If an element contains no data it is called an empty element, e.g. An empty tag may be written more concisely as: For example, the before-mentioned element may be rewritten as:
16
XML Document Structure Cont’d Recommendations The use of elements are preferred over attributes since attributes do not describe structure and are more difficult to manipulate in program code See http://www.w3schools.com/xml/xml_attributes.asp for a comprehensive explanation http://www.w3schools.com/xml/xml_attributes.asp Meta data such as unique identifiers should be stored in attributes For example the use of an id attribute as illustrated in the XML document below The data itself should be stored in elements
17
XML Document Structure Cont’d A Partial XML database: Walcott Paul UWI Cave Hill Campus 417-4372 Male photo1.jpg …
18
XML Parsers There are two main types of XML parsers Parsers that support the Document Object Model (DOM) Parsers that support the Simple API for XML (SAX)
19
XML Parsers Cont’d A DOM parser builds a tree structure in memory that contains the document data A SAX parser processes the document and generates events when certain conditions are met, e.g. When the start of an element is encountered an event is triggered; the software can then read and the element name and its attributes and respond appropriately
20
XML Parsers Cont’d A DOM parser is necessary when the user needs to traverse down an up an XML tree It is slow to load since the entire XML document needs to be read into memory and an XML tree needs to be created On the other hand, SAX parsers are much faster since the document is processed as it is being read No backtracking to parent nodes is allowed
21
XML Parsers Cont’d Some examples of XML Parsers are: msxml – Microsoft’s parser which is built into Microsoft Internet Explorer Xerces – Apache’s XML project’s parser JAXP – Sun Microsystem’s Java API for XML Parsing XML4J – IBM’s XML parser for Java Many of these parsers are freely available
22
XML Parsers Cont’d In the laboratory session you will make use of the DOM parser that is available in your web browser Although the application programmers interface (api) for DOM is complex, the News Feed Reader example explains how to read an XML database and use it in a web page
23
Conclusion In this session the rules for the creation of an XML document were presented In addition, the two main types of XML parsers were compared and contrasted
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.