<Discussion>
XML – Extensible Markup Language
XML eXtensible – add to language. Markup – delimit info using tags. Language – a way to express info.
Major Roles for XML
Store Data XML Document XML Schema
Exchange Data XML Document XML Schema
Client Access to XML Data Present Info XSL Stylesheet 1 XML Document XML Document XSL Stylesheet 2 Client Access to XML Data
Simplify Data Capture (eventually) Database Data encapsulation into data node Insert data node
XML Includes … Marked up text XSD XForms Model XSL Parser XSLT XSL-FO XHTML HTML XPath Rendering Agent XForms Processor
XML Documents -
An XML Document … A text document. Stores data. Data items are delimited using tags. Hierarchical structure. -
Tags: Data: <?xml version="1.0"?> <Customers> <Id>5003</Id> <CName>Jane</CName> <Transaction> <TDate>2003-01-01</TDate> <Amt>-27.85</Amt> </Transaction> <TDate>2003-01-07</TDate> <Amt>49.50</Amt> </Customer> </Customers> Tags: Delimit data. Show meaning. You make tags! Data: Rich data types. Constraints.
Well Formed XML All data items are between tags. Closing tags start with /. Tags are case sensitive. No spaces or symbols in tags. (Data may contain spaces and some symbols.) Tags balance.
Tags and Data <?xml version="1.0"?> <Customers> <Id>5003</Id> <CName>Jane</CName> <Transaction> <TDate>2003-01-01</TDate> <Amt>-27.85</Amt> </Transaction> </Customer> </Customers>
Well Formed? <Cost>123.45<Cost> <Cost><Quantity>123.45</Cost>15</Quantity> <Cost>123.45</Cost><Quantity>15</Quantity> <Cost>Homer Simpson</Cost>
XML Document Structure <?xml version="1.0"?> <Customers> <Customer> <Id>5003</Id> <CName>Jane</CName> <Transaction> <TDate>2003-01-01</TDate> <Amt>-27.85</Amt> </Transaction> <TDate>2003-01-07</TDate> <Amt>49.50</Amt> </Customer> <Id>5004</Id> <CName>Tom</CName> <TDate>2003-03-03</TDate> <Amt>58.85</Amt> </Customers> Customers Customer Id CName 5003 Jane Customer Id CName 5004 Tom Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Transaction TDate Amt 1/3/03 58.85
Hierarchy of Nodes Root Node / Document Element or Document Node Customers Document Element or Document Node Customer Id CName 5004 Tom 5003 Jane Node or Complex Element (Simple) Element Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Transaction TDate Amt 1/3/03 58.85
Key to Understanding? Meaningful, descriptive tag names! 103.95 <z>103.95</z> <Price>103.95</Price> <ListPrice>103.95</ListPrice> <SalesPrice>103.95</SalesPrice> Meaningful, descriptive tag names!
XML Schemas
An XML Schema … Defines the structure of an XML document. Nodes. Hierarchy. Defines the elements in each node. Tag. Data type. Constraints. XML Document XML Schema
Valid XML Document Well formed. XML Document XML document conforms to structure defined in XML schema. XML Schema
XML Schema - Exchange Data Document XML Schema Based on Standards
Identify Data Requirements Defining an XML Schema Agree on Definitions Identify Data Requirements Specify Structure Specify Tags
Some Major XML Standards eXtensible Business Reporting Language (XBRL) Financial Reporting EDI XML/EDI and electronic business using XML (ebXML) EFT Direct Deposit Open Financial Exchange (OFX) Tax Reporting IRS e-file Standards
<?xml version="1.0"?> <Customers> <Customer> <Id>5003</Id> <CName>Jane</CName> <Transaction> <TDate>2003-01-01</TDate> <Amt>-27.85</Amt> </Transaction> <TDate>2003-01-07</TDate> <Amt>49.50</Amt> </Customer> <Id>5004</Id> <CName>Tom</CName> <TDate>2003-03-03</TDate> <Amt>58.85</Amt> </Customers> Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"> <?xml version = "1.0"?> <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"> <xsd:element name = "Customers"> <xsd:complexType> <xsd:sequence> <xsd:element ref = "Customer" maxOccurs = "unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers
<xsd:element name = "Customer"> <xsd:complexType> … <xsd:element name = "Customer"> <xsd:complexType> <xsd:sequence> <xsd:element name = "Id" type = "xsd:string"/> <xsd:element name = "CName" type = "xsd:string"/> <xsd:element ref = "Transaction" maxOccurs = "unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers
<xsd:element name = "Transaction"> <xsd:complexType> … <xsd:element name = "Transaction"> <xsd:complexType> <xsd:sequence> <xsd:element name = "TDate" type = "xsd:date"/> <xsd:element name = "Amt" type = "xsd:decimal"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers
<?xml version = "1.0"?> <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"> <xsd:element name = "Customers"> <xsd:complexType> <xsd:sequence> <xsd:element ref = "Customer" maxOccurs = "unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name = "Customer"> <xsd:element name = "Id" type = "xsd:string"/> <xsd:element name = "CName" type = "xsd:string"/> <xsd:element ref = "Transaction" maxOccurs = "unbounded"/> <xsd:element name = "Transaction"> <xsd:element name = "TDate" type = "xsd:date"/> <xsd:element name = "Amt" type = "xsd:decimal"/> </xsd:schema>
Validating XML Documents Use software or web tools. Topologi Schematron Validator. www.topologi.com GotDotNet Schema Validator. http://apps.gotdotnet.com/xmltools/xsdvalidator/
XSL Stylesheet, etc.
An XSL Stylesheet … Gets and filters nodes in an XML document. Transforms nodes. Formats output.
Many XSL Stylesheets XSL Stylesheet #1 XML Document XSL Stylesheet #2
XSL Stylesheet “Languages” XML Path XSL Transformations XPath: gets nodes using paths and filtering patterns. XSLT: transforms a document tree into a new document tree. XSL-Formatting Objects XSL-FO: describes how output looks. (HTML on steroids!)
Parsed and Rendered Output XML Document XSL Stylesheet + =
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/Customers"> <html> <body> <h1>Customer Information</h1> <xsl:apply-templates select="Customer" /> </body> </html> </xsl:template> <xsl:template match="Customer"> <b>Id: </b> <xsl:value-of select="Id" /><br /> <b>Name: </b> <xsl:value-of select="CName" /><br /> <xsl:apply-templates select="Transaction" /> <br /><hr /><br /> <xsl:template match="Transaction"> <b>Date: </b> <xsl:value-of select="TDate" /> <b>Amount: </b> <xsl:value-of select="Amt" /><br /> </xsl:stylesheet> Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers
Alphabet Soup of Xtechs XForms XML Document XSL Stylesheet XML Schema Languages & Formats XForms Model Marked up text XPath XSL-FO XHTML XSD XSLT HTML Software XForms Processor Editor & Validator XSL Parser Rendering Agent
</Discussion>
Nodes and Elements Customers Customer Id CName Transaction Transaction 5004 Tom 5003 Jane Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Transaction TDate Amt 1/3/03 58.85
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/Customers"> <html> <body> <h1>Customer Information</h1> <xsl:apply-templates select="Customer" /> </body> </html> </xsl:template> <xsl:template match="Customer"> <b>Id: </b> <xsl:value-of select="Id" /><br /> <b>Name: </b> <xsl:value-of select="CName" /><br /> <xsl:apply-templates select="Transaction" /> <br /><hr /><br /> <xsl:template match="Transaction"> <b>Date: </b> <xsl:value-of select="TDate" /> <b> Amount: </b> <xsl:value-of select="Amt" /><br /> </xsl:stylesheet>
<html> <body> <h1>Customer Information</h1> <b>Id: </b>5003<br> <b>Name: </b>Jane<br> <b>Date: </b>2003-01-01<b> Amount: </b>-27.85<br> <b>Date: </b>2003-01-07<b> Amount: </b>49.50<br> <br><hr><br> <b>Id: </b>5004<br> <b>Name: </b>Tom<br> <b>Date: </b>2003-03-03<b> Amount: </b>58.85<br> </body> </html>
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="Customers.xsl"?> <Customers xmlns:mySchema="Customers.xsd"> <Customer> <Id>5003</Id> <CName>Jane</CName> <Transaction> <TDate>2003-01-01</TDate> <Amt>-27.85</Amt> </Transaction> <TDate>2003-01-07</TDate> <Amt>49.50</Amt> </Customer> <Id>5004</Id> <CName>Tom</CName> <TDate>2003-03-03</TDate> <Amt>58.85</Amt> </Customers>
Context and Selection Path / Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers /Customers /Customers/Customer /Customers/Customer/Transaction
Processing Order & Data Exposed / Transaction TDate Amt 1/1/03 -27.95 1/7/03 49.50 Customer Id CName 5004 Tom 5003 Jane 1/3/03 58.85 Customers Customers Customer #1 Customer #2 Transaction #1 Transaction #2 Transaction
Transform and Render XSLT Parser Transformation XPath XSLT Well-formed Tree XSLT Parser XPath Transformation XSLT XSL Stylesheet Well-formed Tree XSL-FO (HTML/CSS) Rendering Agent Rendering
Alphabet Soup of Xtechs XForms XML Document XSL Stylesheet XML Schema Languages & Formats XForms Model Marked up text XPath XSL-FO XHTML XSD XSLT HTML Software XForms Processor Editor & Validator XSL Parser Rendering Agent