Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of...
-
Upload
adele-clarke -
Category
Documents
-
view
213 -
download
0
Transcript of Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of...
Web Technologies Web Technologies COMP6115COMP6115
Session 4: Adding a Database to a Web Session 4: Adding a Database to a Web SiteSite
Dr. Paul WalcottDr. Paul WalcottDepartment of Computer Science, Mathematics and PhysicsDepartment of Computer Science, Mathematics and PhysicsUniversity of the West Indies, Cave Hill CampusUniversity of the West Indies, Cave Hill CampusBarbadosBarbados14/12/06
© 2006/2007 Dr. Paul Walcott
XMLXML22
• Extensible Markup Language (or Extensible Markup Language (or XML) is another markup languageXML) is another markup language
• XML is a subset of SGML (Standard XML is a subset of SGML (Standard Generalised Markup Language)Generalised Markup Language)– SGML is a meta language used to create SGML is a meta language used to create
other languages, e.g. XML and HTMLother languages, e.g. XML and HTML
• The purpose of XML is different from The purpose of XML is different from HTMLHTML
• XML describe data in a structured way and XML describe data in a structured way and is used to define other markup languagesis used to define other markup languages
• XML allows the creation of custom tags XML allows the creation of custom tags (unlike HTML whose tags are predefined)(unlike HTML whose tags are predefined)
• XML uses a DTD to describe the dataXML uses a DTD to describe the data• Several XML standards have been defined, Several XML standards have been defined,
for example to markup mathematical for example to markup mathematical formula, and chemical molecular formula, and chemical molecular structuresstructures
XML Cont’dXML Cont’d
• The The mmain ain ddifference ifference bbetween XML etween XML and HTMLand HTML are: are:11
– XML was designed to carry dataXML was designed to carry data– HTML is about displaying information, HTML is about displaying information,
while XML is about describing while XML is about describing informationinformation
– XML is not a replacement for HTMLXML is not a replacement for HTML
XML Cont’dXML Cont’d
• XML and HTML were designed with XML and HTML were designed with different goals:different goals:– XML was designed to describe data and XML was designed to describe data and
to focus on what data is.to focus on what data is.– HTML was designed to display data and HTML was designed to display data and
to focus on how data looks.to focus on how data looks.
XML Cont’dXML Cont’d
XML Document StructureXML Document Structure22
• XML documents are typically stored in XML documents are typically stored in text files with a .xml extensiontext files with a .xml extension
• An XML document contains one root An XML document contains one root element, which contains all other element, which contains all other elementselements
• The lines preceding the root element are The lines preceding the root element are the prolog of the XML documentthe prolog of the XML document
• Nested elements are called child Nested elements are called child elementselements
• An XML parser is required to process An XML parser is required to process an XML documentan XML document
• The XML parserThe XML parser– Checks the document’s syntaxChecks the document’s syntax– Reports any errorsReports any errors– Allows access to the contents of the Allows access to the contents of the
document through program controldocument through program control
XML Document Structure XML Document Structure Cont’dCont’d
XML Document Structure XML Document Structure Cont’dCont’d• An XML document is well formed ifAn XML document is well formed if
– It has one root elementIt has one root element– It has a start and end tag for each elementIt has a start and end tag for each element
•Except in the case of empty tags that have a Except in the case of empty tags that have a special notation that allows the representation special notation that allows the representation of a start and end tag in a single tagof a start and end tag in a single tag
– The tags are properly nestedThe tags are properly nested•E.g. E.g. <x><y>100</x></y><x><y>100</x></y> is a cross tag while is a cross tag while <x><y>100</y></x><x><y>100</y></x> is properly nested is properly nested
XML Document Structure XML Document Structure Cont’dCont’d
– Attribute values are in quotation marks, Attribute values are in quotation marks, either single or doubleeither single or double
– Elements and attributes are correctly Elements and attributes are correctly capitalised since XML is case sensitivecapitalised since XML is case sensitive
XML Document Structure XML Document Structure Cont’dCont’d
• XML documents typically containXML documents typically contain– Carriage returns,Carriage returns,– LinefeedsLinefeeds– Elements and attributesElements and attributes– Unicode charactersUnicode characters
• XML elements define structureXML elements define structure
• XML attributes describe elementsXML attributes describe elements
XML Document Structure XML Document Structure Cont’dCont’d
• An element may have zero or more An element may have zero or more attributesattributes
• Attributes are placed within the the Attributes are placed within the the start tagstart tag
• Attribute values are enclosed in Attribute values are enclosed in single or double quotessingle or double quotes
XML Document Structure XML Document Structure Cont’dCont’d
• Element and attribute names:Element and attribute names:– May be of any lengthMay be of any length– May contain letters, digits, underscores, May contain letters, digits, underscores,
hyphens and periodshyphens and periods– Must begin with a letter or underscoreMust begin with a letter or underscore
•Spaces are not allowed in element or Spaces are not allowed in element or attribute namesattribute names
XML Document Structure XML Document Structure Cont’dCont’d• If an element contains no data it is called If an element contains no data it is called
an empty element, e.g.an empty element, e.g.– <person name=“Fred”></person><person name=“Fred”></person>
• An empty tag may be written more An empty tag may be written more concisely as:concisely as:<<ElementNameElementName AttributesAttributes/>/>
• For example, the before-mentioned For example, the before-mentioned element may be rewritten as:element may be rewritten as:– <person name=“Fred”/><person name=“Fred”/>
XML ParsersXML Parsers
• There are two main types of XML There are two main types of XML parsersparsers– Parsers that support the Document Parsers that support the Document
Object Model (DOM)Object Model (DOM)– Parsers that support the Simple API for Parsers that support the Simple API for
XML (SAX)XML (SAX)
XML Parsers Cont’dXML Parsers Cont’d
• A DOM parser builds a tree structure in A DOM parser builds a tree structure in memory that contains the document memory that contains the document datadata
• A SAX parser processes the document A SAX parser processes the document and generates events when certain and generates events when certain conditions are met, e.g.conditions are met, e.g.– When the start of an element is encountered When the start of an element is encountered
an event is triggered; the software can then an event is triggered; the software can then read and the element name and its read and the element name and its attributes and respond appropriatelyattributes and respond appropriately
XML Parsers Cont’dXML Parsers Cont’d
• Some examples of XML Parsers are:Some examples of XML Parsers are:– msxml – Microsoft’s parser which is built msxml – Microsoft’s parser which is built
into Microsoft Internet Explorerinto Microsoft Internet Explorer– Xerces – Apache’s XML project’s parserXerces – Apache’s XML project’s parser– JAXP – Sun Microsystem’s Java API for XML JAXP – Sun Microsystem’s Java API for XML
ParsingParsing– XML4J – IBM’s XML parser for JavaXML4J – IBM’s XML parser for Java
• Many of these parsers are freely Many of these parsers are freely availableavailable