Session I Chapter 1 – Writing XML http://www.profburnett.com CMP 051 XML Introduction Session I Chapter 1 – Writing XML http://www.profburnett.com
Outline XML Rules XML Basic Components XML Tree XML Syntax Rules XML Elements XML Attributes XML Comments XML Encoding Predefined Entities 8/1/2014 Copyright © Carl M. Burnett
XML Rules Platform independent Software independent Vendor and technology-independent metalanguage Designed to deliver structured content over the Web 1/1/2019 Copyright © Carl M. Burnett
XML Basic Components An element is the basic building block Each element begins with a start tag and ends with an end tag Attributes are specifications for elements. They appear as name-value pairs Elements may or may not require attributes 8/1/2014 Copyright © Carl M. Burnett
XML Tree 8/1/2014 Copyright © Carl M. Burnett Root Element <bookstore> Element <book> Element <Title> Attribute “lang” Text: Everyday Italian Element <Year> Text: 2005 Element <Author> Text: Giada De Laurentis Element <Price> Text: 30.00 Attribute <category> 8/1/2014 Copyright © Carl M. Burnett
XML Tree Root element = <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <price>29.99</price> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </bookstore> XML Tree Root element = <bookstore> All <book> elements in <bookstore> document 4 children: <title> <author> <year> <price> 8/1/2014 Copyright © Carl M. Burnett
XML Syntax Rules XML is case-sensitive Root Element is required All opening tags must have a corresponding closing tag, or a terminating slash on opening tag No overlapping of tags can occur All attribute values must be enclosed in single or double quotation marks 8/1/2014 Copyright © Carl M. Burnett
XML Syntax Rules An application profile Defines XML-related languages for a specific organization or industry Creates specific document types for XML-related languages and develops applications to handle those documents The tagged data can be used for creation, management, and maintenance of large collections of complex information 1/1/2019 Copyright © Carl M. Burnett
XML Elements Root Element Child Element Nesting Elements <$xml version=“1.0”?> <bookstore> ……… </bookstore> Root Element Child Element Nesting Elements <$xml version=“1.0”?> <bookstore> <book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore> <$xml version=“1.0”?> <bookstore><title>Harry Potter</title></bookstore> 8/1/2014 Copyright © Carl M. Burnett
XML Attributes Same Rules as Element Names No Two Attributes with same name Must be in Quotes Treat Attributes as “Metadata” bookstore> <book category="CHILDREN“> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore> 8/1/2014 Copyright © Carl M. Burnett
XML Attributes (Metadata) Different was to use <note> <date>10/01/2008</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note date="10/01/2008"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note> <date> <day>10</day> <month>01</month> <year>2008</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> 8/1/2014 Copyright © Carl M. Burnett
XML Comments <!-- This is a comment --> 8/1/2014 Copyright © Carl M. Burnett
XML Encoding <?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8"?> (8-bits) - Web <?xml version="1.0" encoding="UTF-16"?> (16-bits) 8/1/2014 Copyright © Carl M. Burnett
Predefined Entities Code Type Description < less than > greater than & & ampersand ' ' apostrophe " " quotation mark 8/1/2014 Copyright © Carl M. Burnett
XML Examples An XML CD catalog An XML plant catalog A Simple Food Menu 8/1/2014 Copyright © Carl M. Burnett
Review XML Rules XML Basic Components XML Tree XML Syntax Rules XML Elements XML Attributes XML Comments XML Encoding Predefined Entities Next – Session II – Chapter 2 - XSLT 8/1/2014 Copyright © Carl M. Burnett
Student Exercise 1 Dreamweaver Environment Setup Setup your Dreamweaver environment with the parameters provided. Setup local development folder on GBTC share drive. setup live site on MC Web4forStuents website using environment setup parameters provided 8/1/2014 Copyright © Carl M. Burnett
Student Exercise 2 - Create XML File Create a contacts XML file using data in contacts PDF. Synchronize your local development site with your live site. 8/1/2014 Copyright © Carl M. Burnett