Presentation on theme: "SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport."— Presentation transcript:
Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport and store data (carry) ◦HTML was designed to display data (show) ◦Shares common structure with HTML documents ◦Elements are indicated with markup tags that contain textual content; element names are descriptive ◦A markup tag can contain attributes that describe a feature of the element, and a single root element contains all other elements in the document
Introducing XML XML does not DO anything. XML was created to structure, store, and transport information. The following example is a note to Tove, from Jani, stored as XML Tove Jani Reminder Don't forget me this weekend!
XML Tree Structure With XML You Invent Your Own Tags ◦the XML language has no predefined tags XML documents form a tree structure that starts at "the root" and branches to "the leaves"..
Introducing XML XML declaration It defines the XML version (1.0) and the encoding used (UTF-8). Single root element (students) Student, name, and photo elements and the id and grade attributes provide information about individual students
Syntax Rules o Must have closing tags o Case sensitive tags o Proper tag nesting o Must have a Root element o Attributes must be quoted o Uses HTML comments o Special symbols > < & ‘ “ o Use entity references: < >
Syntax Rules Comments are similar to HTML comment White-space is Preserved in XML Naming rules ◦XML elements must follow these naming rules: ◦Names can contain letters, numbers, and other characters ◦Names cannot start with a number or punctuation character ◦Names cannot start with the letters xml (or XML, or Xml, etc) ◦Names cannot contain spaces ◦Any name can be used, no words are reserved
XML Elements An XML element is everything from (including) the element's start tag to (including) the element's end tag An element can contain: ◦other elements ◦text ◦attributes ◦or a mix of all of the above Harry Potter J K. Rowling 2005 29.99
XML attributes XML elements can have attributes. ◦Attributes provide additional information about an element. computer.gif
XML Elements vs. Attributes Take a look at these examples: Anna Smith female Anna Smith
Attributes vs. Elements Some of the problems with using attributes are: ◦attributes cannot contain multiple values (elements can) ◦attributes cannot contain tree structures (elements can) ◦attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain ◦Use elements for data, and attributes for information that is not relevant to the data
Namespaces XML Namespaces provide a method to avoid element name conflicts Defined by the xmlns attribute Tags that are not HTML tags have the prefix xsl, identified by the namespace xmlns:xsl="http://www.w3.org/1999/XSL/Transform": Name conflicts in XML can easily be avoided using a name prefix xmlns:h="http://www.w3schools.com/html4"> xmlns:f="http://www.w3schools.com/furniture">
eXtensible Style sheet Language Translation.XSLT
Styles Can use a CSS style sheet to format an XML document Better approach is to use XSL (eXtensible Stylesheet Language) ◦can transform an XML document into HTML, using ◦XSLT (eXtensible Stylesheet Language Transformation)
Transforming XML with XSLT Extensible Stylesheet Language Transformation (XSLT) ◦A style language developed for XML documents ◦Allows developers to easily transform contents of an XML document into another document format ◦A more efficient approach to transforming an XML document into HTML format than working with the document object model
The Element The match attribute is used to associate a template with an XML element match="/" indicates the stylesheet template applies to the entire XML file My CD Collection Title Artist..
Used to extract the value of an XML element and add to output. My CD Collection Title Artist
The Element Allows you to do looping My CD Collection Title Artist
XSLT Element used to sort the output My CD Collection Title Artist
XSLT Element used to put a conditional test against the content of the XML file My CD Collection Title Artist