170 likes | 348 Views
XML, XSL, XSLT, XHTML and others. By Sean Hunter. Why XML?. XML was created to be a quick and easy way to provide structured data over the web. Existing HTML and SGML either did not allow arbitrary structure, or were too complex.
E N D
XML, XSL, XSLT, XHTML and others By Sean Hunter
Why XML? • XML was created to be a quick and easy way to provide structured data over the web. • Existing HTML and SGML either did not allow arbitrary structure, or were too complex. • XML’s simplicity allows programmers to write parsers for it quickly and easily.
What is XML? • Extensible Markup Language • XML is a human readable database • XML is fully conformant SGML, but XML parsers do conform to all of SGML. • As any markup language, XML provides a way to create structure in a document
Elements of XML • XML declaration: • <?xml version="1.0"?> • Not required, however it provides information on how to process the XML document • Tags: <A></A>, </A> • Attributes: </A name=“B”> • Values: <A>A’s Value</A>
Example <?xml version="1.0"?> <list name=“Count”> <item>One</item> <item>Two</item> <item> <list> <item>One</item> </list> </item> </list>
Document Type Definitions • Provides a way to standardize an XML document • Declares what elements can exist, what elements can nest in other elements, how many of a element are allowed, what attributes are allowed on a element, etc.
Example <!ELEMENT LIST (ITEM*)> <!ELEMENT ITEM (#PCDATA|LIST)> The * means that a LIST element may contain zero or more ITEM’s. ITEM may contain either text (#PCDATA) or another LIST element.
XSL and XSLT • Extensible Stylesheet Language Transformations • Provides a method to transmute XML into already existing data structures such as HTML, PDF, GIF, etc. • Sometimes companies want to keep the XML hidden, and only provide the transmuted data, or simply provide a more humanly readable format of their data.
Example - XML <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href=“motd.xsl"?> <motd>xml.com</motd>
Example - XSLT <?xml version="1.0"?> <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <body> Current message of the day: <i><xsl:value-of select=“motd"/></i> </body> </html>
Result Current message of the day: xml.com
XHTML • One major problem that many web designers have is that their website will look different across multiple different web browsers. Something on Firefox may look different from something on Opera, and IE. • XHTML creates a much stricter form of HTML that should, ideally, only have one way to be displayed across all browsers. • Because HTML does not have to be valid form for a browser to display it, XTML is preferred on cell phones and similar devices due to needing less processing to fix broken code.
RDF • RDF: Resource Description Framework • A possible way of describing resources in the internet. • Ex (From xml.com): <rdf:Description about='http://www.textuality.com/RDF/Why-RDF.html'> <Author>Tim Bray</Author> <Home-Page rdf:resource='http://www.textuality.com' /> </rdf:Description>
RSS • RDF Site Summary • A news feeder that many websites use to provide information about news on their website in a standard format using XML.
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>XML.com</title> <link>http://www.xml.com/</link> <description>XML.com features a rich mix of information and services for the XML community.</description> <language>en-us</language> <item> <title>Normalizing XML, Part 2</title> <link>http://www.xml.com/pub/a/2002/12/04/normalizing.html</link> <description>In this second and final look at applying relational normalization techniques to W3C XML Schema data modeling, Will Provost discusses when not to normalize, the scope of uniqueness and the fourth and fifth normal forms.</description> <dc:creator>Will Provost</dc:creator> <dc:date>2002-12-04</dc:date> </item> • </channel> • </rss>
XPath/XQuery • XPath: Used in XSL to find a particular element. Ex: body//p[position()=1] to get the first <p> element in <body> • XQuery: A programming language for use in XML • Example, combining XPath and XQuery to print the chapters in a book from an XML structure (Taken from xml.com): <html>{ let $book := document("mybook.xml")/book for $ch in $book/chapter return <h2>{$ch/title)</h2> }</html>
References • O’Reilly’s XML.com • World Wide Web Consortium W3C.org