1CMSC 330: Organization of Programming LanguagesMarkup & Query LanguagesCMSC 330 2Other Language TypesMarkup languages•Set of annotations to textQuery languages•Make queries to databases & information systemsUsed together in •Web interface to databasesCMSC 330 3Markup LanguagesSet of annotations (tags) added to text•Example – <tag> text </tag>Describe how text is•Structured, laid out, formatted…First used in publishing industry•Typesetting, proofreadingnroff, troff, TeX, LaTeX•Mostly replaced by WYSIWYG editors like MS WordWhat you see is what you getRegained importance with advent of web•Used to describe format & presentation of web pagesCMSC 330 4History of Markup LanguagesGML (1960s)•Generalized markup language•Describe both structure & presentation of contentHTML (1991)•Hypertext markup language •Flexible & simple descriptive markup for web pages•Hypertext links parts of document to other documentsCMSC 330 5History of Markup Languages (cont.)XML (1998)•Extensible markup language•Language for describing tags (meta-language)•User can create tags and describe their uses•Used to describe documents w/ structured information•No mechanism for displaying XML documentCMSC 330 6Markup Language – GMLExample:h1.Recipes: :p.Bread:ol:li.Flour:li.Yeast:li.Water:eol.2CMSC 330 7Markup Language – HTMLExample<html><head><title>Bread Recipe</title></head><body><h1>Bread</h1><ol><li>Flour<li>Yeast<li>Water</ol></body></html>CMSC 330 8Markup Language – XMLExample<recipe name=“Bread”> <title>Bread</title><ingredient>Flour </ingredient><ingredient>Yeast</ingredient><ingredient>Water</ingredient></recipe>CMSC 330 9HTML / XML ElementsElement•A start tag, an end tag, and data in between•Examples<director> Tyler Perry </director><actor> Tyler Perry </actor>Attribute•A name-value pair separated by an equal sign (=)•Used to attach additional information to an element•Example<city ZIP=“20742”> College Park </city>CMSC 330 10HTML ElementsStructural•Describes purpose of text•Examples<h1> Level 1 heading <h1><ol> Ordered list </ol><ul> Unordered list </ul><li> List item </li>CMSC 330 11HTML Elements (cont.)Presentation•Describes appearance of text•Examples<b> boldface </b><i> italics </i><p> line spacing </p>Hypertext•Links part of document to other documents•Examples<a> Anchor </a><a href=“http://www.cs.umd.edu”> URL link </a>CMSC 330 12XML DocumentAn XML element with nested XML elements•Example<movies><movie year=“2005”><title> Diary of a Mad Black Woman </title><director> Tyler Perry </director></movie><movie year=“2006”><title> Madea's Family Reunion </title><director> Tyler Perry </director></movie></movies>3CMSC 330 13XML Documents (cont.)Guidelines•Elements must have an end tag (unlike HTML)•Elements must be cleanly nestedOverlapping elements are not allowed•Attribute values must be enclosed in quotation marks•Document must have unique first element (root node)Document Type Definition (DTD) •User can create set of rules to specify legal content•Place restrictions on XML fileCMSC 330 14Comparing HTML With XMLHTML•Fixed set of tags•Presentation oriented•No data validation capabilities•Single presentationXML•Extensible set of tags•Content oriented•Standard Data infrastructure •Multiple output formsCMSC 330 15Using Markup LanguagesDescriptive markup•StructureHow is this organized? (<chapter>, <section>)•SemanticsWhat is this? (<person>, <title>)Separate presentation from content•Keep presentation elsewhere (CSS, XSL)•Puts content in “delivery neutral format”<h1> is a first level heading, but can be any fontCMSC 330 16Markup Language UsageStarted with documentsNow also used to organize•MetadataData about data, used to help understand / manage dataExample: <LastName optional=“true”> Smith </LastName>•TransactionsSingle unit of work for application•ApplicationsHelping applications interact / work togetherCMSC 330 17Query LanguagesMake queries to •Databases•Information systemsGoals•Data retrieval•Data managementExamples•SQL (1970s) – Query relational databases•LDAP (1993) – Query directory services for TCP/IPCMSC 330 18Databases (DB)A structured collection of data (records)•Whose content can be quickly and easilyAccessed, managed, updatedDatabase model•HierarchicalRecords are stored in a tree•NetworkRecords have links to other records•RelationalRecords are stored in tables (relations)4CMSC 330 19Tables (Relations)Each column constitutes an attributeEach row constitutes a record or tupleAttribute 2(column 2)Record 2(tuple 2)Record 1(tuple 1)Attribute 1(column 1)$45KComputer ProgrammingRecord 2$37K$56K2007 StartingSalaryBiologyRecord 3Computer EngineeringRecord 1MajorCMSC 330 20SQL (Structured Query Language)Queries for relational database systemsAllows for complete•Table creation, deletion, editing•Data extraction (queries)•Database management & administrationCMSC 330 21SQL – Creating DatabaseTypes of attributes•char, varchar, int,, decimal, date, etc.•varchar is a string with varying # of charsNot Null•Each record must have valuePrimary key •Must be unique for each recordCREATE TABLE tableName (name VARCHAR(55),sex CHAR(1) NOT NULL,age INT(3),birthdate DATE,primary key(name));CMSC 330 22SQL – Creating Database (cont.)Primary key •Can use autoincrementednumbers as primary key•Guaranteed to be unique•1stentry key = 1•2ndentry key = 2, etc…CREATE TABLE tableName (name VARCHAR(55),sex CHAR(1) NOT NULL,age INT(3),birthdate DATE,id INT AUTO_INCREMENT, primary key(id));CMSC 330 23SQL – Inserting ValuesIdentical resultOrder of fields do not matterINSERT INTO tableName (name, sex, age) VALUES (‘Bob’, ‘M’, 42);INSERT INTO tableName (age, name, sex,) VALUES (42, ‘ Bob’, ‘M’);CMSC 330 24SQL – Updating ValuesOperations in the form•Select …•From …•Where …Means•Select a column•From a database•Where x meets y conditionUPDATE tableNameSET age = ’52’WHERE name LIKE ‘Bob’5CMSC 330 25Database ServerAccepts requests to access database•Requests in query language (e.g., SQL)MySQL•Multithreaded•Multiuser•SQL database management system (DBMS)•Open sourceFree download of Community Edition CMSC 330 26Database Web InterfaceRequires•Database server (MySQL)•Web server (Apache)•Method of connecting two
View Full Document