XML Extensible Markup Language
Today: Imagine Cup –Wednesday, February 2nd from 6-8 pm in Lally Hall, Room 104, we will have a representative on campus for the Imagine Cup Program. Pizza and soda will be provided. Homework #1 XML In class: define your class schedule in XML (groups ~10) Tuesday: XSLT (reformatting XML)
Standards Help or hinder innovation? Think about it
Standards –HTML, CSS, XML, XPATH, SVG, Services, Semantic Web –URNs, DNS, IP Addresses –HTTP, TCP/IP –Ethernet, , MAC addresses
Standards NTSC –1936, industry recommendation –1941, B&W standard –1950, color standard –2009, FCC required shutdown of NTSC broadcast
Standards Standards in Physical Infrastructure –European vs. US cell phone technology adoption rates (one euro standard v. 3 in the US) –Gas Stations & alternate fuels for personal transportation
Standards Help or hinder innovation? Ok, lets have a discussion
XML Organize Data –Consistent Syntax –Semantic Free
Stuff we do with XML machine to machine transfer of models & data data storage (best for storing data in a tree format) sending data from the application to the presentation layer
KML / AJAX Example Google maps consumes KML Outputs JS / XHTML / CSS Structured data can be reused.
An Example XML Doc
Some Common XML types Atom –Which is really cool because it can hold other formats within it RSS Itunes Library KML XHTML…
XHTML A specific flavor of XML Defined by a DTD (Document Type Definition) – strict.dtd
XML documents must be: Well-formed –Adhere to XML syntax rules Valid –Adhere to the rules in the specified DTD
Root / Parents Elements must have a parent Documents must have one document root is the only top level element. It is the document root
XML Syntax Rules Elements must have a closing tag: –... – Self closing tags
Proper Nesting of Elements: blah blah
Element Naming Rules Elements are lowercase only Elements must not start with “xml” Element names should not contain “-” or “:”
Attributes Elements describe data Attributes describe elements Attributes must be in quotes Examples
Namespaces Used to prevent element or attribute name or ‘meaning’ collisions Example Namespace collision Two namespaces namespace nameelement name
Namespaces Pointing to a namespace xmlns attribute In –an element –global definition
Namespaces In an element (applies to all of its children)
Namespaces Global <html xmlns:h=“ xmlns:m=" >.. Some text
Namespaces + Standards Decisions are expensive Use a preexisting format (no limit to number of namespaces on a page) xml-guidelines/ xml-guidelines/
DTD Document Type Definition Internal or external file describing list of elements, attributes and their relationships. Machine readable
DTD Building Blocks Elements (describe data) Attributes (describe elements) PCDATA (the stuff between tags that gets parsed) CDATA - (data between tags that contains other data that you do not want parsed) Entities - (special items, such as & )
DTD Elements Defining an element element name type
DTD Elements Defining an empty element (no closing tag) Defining an element with children
DTD Attributes Setting a default setting the default colspan value to 1 in a element
DTD Attributes required attribute & implied attribute XML author must include a value for page to validate author does not have to include attribute/value and we aren't setting a default either
DTD & Standards Load: transitional.dtd transitional.dtd Look at line 273 What are the first children elements allowed inside
DTD & Standards Validator compares rules in the DTD with the XML implemented.
DTD Entities Exist in XML like this & + name + ; lt, jt, amp, apos, quot are supported by defualt DTD author can specify custom entities to operate as replacement variables –Example: &myname; –(replacement defined in the DTD)
XHTML Entities s.asphttp:// s.asp 5 ‘Reserved Characters’ must not be part of your page content … use HTML entities instead
Entities JS or XSLT –Watch less than / greater than Input you don’t control –Watch everything!! Wrap data in CDATA
Entities Wrap data in CDATA (will not be parsed)
Entities hi ]]> Would display as hi
Entities <?PHP $good = htmlentities ($bad); ?>