1 / 25

XML

XML. by Jon Pearce. What is XML?. XML = eXstensible Markup Language = a meta language for defining markup languages. Examples:

sue
Download Presentation

XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML by Jon Pearce

  2. What is XML? XML = eXstensible Markup Language = a meta language for defining markup languages. Examples: MathML, SVG (Scalable Vector Graphics), WML (Wireless Markup Language), XBRL (Extensible Business Reporting Language), XUL (Extensible User Interface Language), PDML (Product Data Markul Language), CML (Chemical ML), VoiceXML, VML (Vector ML), cXML (Commerce XML), tpaML (Traqding partner agreement XML), SMBXML (Small to Medium Business XML), FinXML (Financial XML), SOAP, XHTML, OWL

  3. XML History • Standard Generalized Markup Language • Invented in 1980s for publishing industry • Markup meta language • HTML is an SGML language • Ancestor of XML

  4. Uses of XML • Data Storage • Object Serialization • Presentation Independent • Language Independent • Application Initialization • Message Passing • Between Tiers • Data-Business-Presentation-Client • SOAP and Web Services

  5. An XML Document Contains: • A Prolog • Elements <tag> content </tag> • Comments <!-- don't read this --> • CDATA Sections <![CDATA[ pre-formatted text]]> • Processing Instructions (PIs) <? do it ?>

  6. Format of an XML Document <?xml version="1.0"?><root> ELEMENT ELEMENT ...</root>

  7. Tree Structure of an XML Document

  8. A Document Prolog Contains: • XML Declaration <?xml version="1.0" ?> • DTD (optional) • Style Sheet (optional) • etc. <?xml version="1.0"?><!DOCTYPE addresses SYSTEM "addresses.dtd"><?xml-stylesheet type="text/xsl" href="addresses1.xsl"?>

  9. An XML Element Contains: • <TAG attributes> content </TAG> <DATE status="cancelled"> 09/01/2002</DATE> • An empty element: <TAG attributes />

  10. Example: book.xml <?xml version="1.0"?><addresses> PERSON PERSON PERSON ...</addresses>

  11. A Person Element (1) <person> NAME ADDRESS PHONE</person>

  12. A Person Element (2) <person> <name> <first> Joe </first> <last> Smith </last> </name> <address> <street> 123 Sesame St </street> <city> New York </city> <state> NY </state> </address> <phone> (555) 555-1234 </phone> </person>

  13. Displaying XML in IE

  14. Grammars • G = a grammar • L(G) = Language defined by G • w L(G) means w is a valid L(G) sentence • Example: • G = English grammar • G = Java grammar

  15. Grammar Rules • An EBNF grammar is a list of rules of the form: • PARENT ::= CHILDREN • CHILDREN is a regular expression: • A B, A | B, A*, A?, 'leaf'

  16. Addresses EBNF ADDRESSES ::= PERSON*PERSON ::= NAME ADDRESS PHONENAME ::= FIRST LASTADDRESS ::= STREET CITY STATEPHONE, FIRST, LAST, STREET, CITY, STATE ::= STRING

  17. addresses.dtd <!ELEMENT addresses (person*)><!ELEMENT person (name, address, phone)><!ELEMENT name (first, last)><!ELEMENT first (#PCDATA)><!ELEMENT last (#PCDATA)><!ELEMENT address (street, city, state)><!ELEMENT street (#PCDATA)><!ELEMENT city (#PCDATA)><!ELEMENT state (#PCDATA)><!ELEMENT phone (#PCDATA)>

  18. book.xml (with a dtd) <?xml version="1.0"?><!DOCTYPE addresses SYSTEM "addresses.dtd"><addresses> PERSON PERSON PERSON ...</addresses>

  19. Well Formed vs. Valid Documents • Validating Parsers determine if an XML document conforms to its DTD • Non-validating parsers merely determine if an xml document is well formed

  20. Extensible Style Sheet Language • XSL is an XML language for describing a transformation • An XSL document describes a transformation that transforms XML documents into xHTML documents

  21. XSL Format <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"><xsl:template match="/"> HTML + XML instructions </xsl:template></xsl:stylesheet>

  22. XSL Markup • <xsl:for-each select=TAG> ... </for-each> • selects each element in an XML document matching TAG and performs ... • <xsl:value-of select=TAG /> • Displays the value of TAG

  23. addresses.xsl <html><head><title> Addresses </title></head><body>Here are your addresses:<xsl:for-each select="addresses/person"> <br /><hr /> <font color="red"> <b><i> name = <xsl:value-of select="name"/> </i></b> </font> <br /> phone = <xsl:value-of select="phone"/></xsl:for-each> <br /><hr /></body></html></xsl:template> </xsl:stylesheet>

  24. book.xml (with an xsl) <?xml version="1.0"?><!DOCTYPE addresses SYSTEM "addresses.dtd"><?xml-stylesheet type="text/xsl" href="addresses.xsl"?><addresses> PERSON PERSON PERSON ...</addresses>

  25. Displaying book.xml in IE (2)

More Related