600 likes | 767 Views
XML Extensible Markup Language: An Introduction The Enabling Technology for B2B eCommerce and Web Site Development. Minder Chen, Ph.D. Associate Professor of Management Information Systems and Decision Sciences School of Management, George Mason University E-Mail: mchen@gmu.edu
E N D
XMLExtensible Markup Language: An Introduction The Enabling Technology for B2B eCommerce and Web Site Development Minder Chen, Ph.D. Associate Professor of Management Information Systems and Decision Sciences School of Management, George Mason University E-Mail: mchen@gmu.edu Phone: 703-993-1788 Fax: 703-993-1809
Workshop Outline • B2B E-Commerce • XML Basics • XML Document Type Definition, Schema, and Data Type • XSL (eXtensible Style Language) • Access XML via Scripting and XML Document Object Model (DOM) • Server-Side XML Processing • XML Usage in B2B
References • William J. Pardi, XML in Action, Microsoft Press, 1999. • Alex Homer, XML IE5: Programmer's Reference, WROX, 1999. • Elliotte Rusty Harold, XML Bible, IDG Books, 2000. • Online resources: • Our XML resources: • http://65.168.115.6/xml/ • Microsoft XML resources: • http://msdn.microsoft.com/xml/ • Dedicated XMl sites: • http://www.xml.com/ and http://www.xmlsoftware.com/ • XML-Data standard • http://www.w3.org/TR/1998/NOTE-XML-data/ • XML namespaces: http://www.w3.org/TR/REC-xml-names/ • XSL standard: http://www.w3.org/TR/1998/WD-xsl-19981216.pdf • The World Wide Web Consortium XML Workgroup: http://www.w3.org/XML/Activity • Timothy Bray's (co-editor of the XML spec.) XML page • http://www.textuality.com/xml/
Buying and Selling– Primitive Document / Data Interchange and Workflow Review Identify Send Select Approve Set Up Catalogs Specifications RFP Vendor P.O. Credit Define Review Fill Out Send P.O. Requirements Vendors P.O. to Vendor Check Availability Letter of Prepare Generate P.O. Credit/Terms Fulfillment Receipt Send Invoice Arrange Send Receive Prepare Shipping Order Order Invoice Receive Invoice/ Prepare Payment Tariffs/ Inspections Customs Post Send Payment Check
HTML and XML Courselist.xml Courselist.htm Courselist.doc XML <?xml version="1.0" ?> <courselist> <course level="basic"> <firm>AITC</firm> <title>Intr. to XML</title> <date>May 29, 1999 </date> <price currency="USD"> 220 </price> <location>Reston Lab </location> </course> </courselist> HTML <html><head><title>Course List</title></head> <body> <ol> <li>Course List <ul> <li> AITC offers <li> Intr. to XML <li> basic-level <li> May 29, 1999 <li> Price $220 <li> Reston Lab </ul> </ol> </body></html> Plain English Course List: AITC offers Intr. to XML a basic-level course on May 29, 1999 Price $220 at Reston Lab
XML Document Containing an Internal Document Type Definition <?xml version=“1.0” standalone=“yes” ?> <!DOCTYPE person [ <!ELEMENT person ( name, street ) > <!ELEMENT name ( #PCDATA ) > <!ELEMENT street ( #PCDATA ) > ]> <person> <name> Minder Chen </name> <street> 100 Main St. </street> </person> http://www.commerceone.com/xml/cbl/docs/purchaseorderdtdsamp.html
XML • Extensible Markup Language (XML) 1.0 • W3C Recommendation 10-Feb-98 A meta-language for defining XML DTD. XML Schema is a competing standard. XML 1.0 Recommendation For a specific type of document such as a definition of Purchase Order's data structure. It is used to validate XML document. XML DTD For a specific document such as a specific Purchase Order. XML Document
Document Receiver: John Sender: Harry Subject: Hello ============================ Dear John, Hello! ……………… ... This is the document for you! Harry May 12, 1999 • Structure • Content • Display Simple E-mail document
HTML, SGML and XML? • Relations between HTML, SGML and XML: • HTML is an implementation(instance) of SGML • XML is an subset of SGML • They are all languages for “document” processing Instances /Domains RDF CDF CML ... XML HTML ... SGML
So, You Need More Than XML… Structure DTD XML Parser Validation Document with Special Format (HTML/CSS) XML document Processing Content Display XSL
HTML vs. XML HTML XML The markup describes the way in which the data is to be displayed in the browser. The markup describes the data itself. Developers must use a limited set of predefined tags. Developers create tags and can therefore describe any type of data. Searching for and updating data is difficult because the same set of tags can be used for different types of data. Searching for and updating data is easy because each type of data has a unique set of tags that define it. The way in which data is to be displayed in the browser is controlled. XML does not have any control over the way data is displayed.
Benefits from XML • Extensible Markup Language is a text-based format that lets developers describe, deliver and exchange structured data between a range of applications to clients for local display and manipulation. • Information will be more accessible and reusable. • XML brings so much power and flexibility to Web-based applications for exchanging "structured data" • Data integration from disparate sources • Data from multiple applications • Local computation and manipulation of data • Multiple views on the data More Meaningful searches • Open Standards • Format for Web delivery • Enhances scalability • Facilitates compression
Well-Formed XML • Must start with an XML declaration • Non-empty tags must match and nest properly • Empty tags must end with /> • Must have exactly one root element • Tag and attribute names are case-sensitive • Attribute values must be quoted
Sample XML Document <?xml version="1.0"?> <PLANT ZONE="3"> <COMMON>Columbine</COMMON> <BOTANICAL>Aquilegia canadensis</BOTANICAL> </PLANT> A string literal was expected, but no opening quote character was found. Line 3, Position 13 <PLANT ZONE=3> ------------^
So What!? • "You guys look like a bunch of geniuses, and all you did was say, 'Make the tags balance.' " --- A Silicon Valley executive • "There is really not much technology in XML, and even less that is new. But there are a few touches that while small, have been crucial." • XML is text, not binary. • Superior error-handling • Internationalization --- Tim Bray
XML Technologies Definition and Structure XML Data Types XML Schema DTD Data Store Display and Reporting XML XSL Data Transfer Application HTML/CSS Link to other resources XPL XLL HTML XML Resources
XML Document: Namespaces • Namespaces provide ways to mix XML tags without chaos • Example: <widget xmlns="http://www.widget.org" xmlns:xhtml="http://www.w3.org/TR/xhtml1" type="gadget"> <head size="medium"/> <big><subwidget ref="gizmo"/></big> <info> <xhtml:head> <xhtml:title>Description of gadget</xhtml:title> </xhtml:head> <xhtml:body> <xhtml:h1>Gadget</xhtml:h1> A gadget contains a big gizmo </xhtml:body> </info> </widget>
Creating XML Using XML Notepad • You can find the latest information on XML Notepad at the Microsoft website at http://www.microsoft.com/
Source Document <PRODUCTLIST> <PRODUCT> <ID>html100</ID> <NAME>Introduction to HTML</NAME> <PRICE>$200</PRICE> </PRODUCT> <PRODUCT> <ID>xml100</ID> <NAME>Introduction to XML</NAME> <PRICE>$250</PRICE> </PRODUCT> </PRODUCTLIST>
XML Document: Validation • You can enforce rules about these tags. Two kinds of ways to define rules for the document. These rules can be used to validate an XML document or used by XML authoring tools to guide the creation of an XML document. • Document Type Definition (DTD): The XML DTD contains or points to markup declarations that provide a grammar for a class of documents. It uses a special non-XML-based grammar • XML Schema (XML-Data): This is a much richer and more extensible way to describe the rules for the content of a document and uses XML itself as a grammar.
XML Document Structure <?xml version="1.0"?> <!DOCTYPE book SYSTEM "bookreview.dtd” > <book> <author> Jane Smith </author> <review> . . . </review> </book> <!-- “book” is the root element.--> <?imgsize size=“200,200” ?> • Prologue: • XML declaration • Document Type Declaration (DOCTYPE) • Processing Instructions and Comments • Root Element and its child nodes • Epilogue: • Comments and • Processing Instructions
XML Document with an Internal DTD <?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)>]><greeting>Hello, world!</greeting> Internal DTD: <!DOCTYPE rootElement [ elementDeclarations ]> Standalone attribute indicates whether external entities impact the information passed to the processing application
Anatomy of a Tag <H1 ALIGN="CENTER"> XML Tutorial </H1> <H1 ALIGN="CENTER"> XML Tutorial </H1> Attribute Closing tag Opening tag Element
DTD (Document Type Definition) • DTD defines the valid structure of XML document rules such as: • Valid element names<BOOK><TITLE><AUTHOR><PRICE><ISBN> • Valid attribute names and values <AUTHOR id="234" gender="F"> • Relationship between elements (Child elements) • <BOOK> <TITLE>...</TITLE> <AUTHOR>...</AUTHOR> …………...</BOOK> • DTD can be included within XML document or included from other file/document
It’s Complex, but More Powerful • With DTD you can… • Define your own more meaningful tags • easy to read • easy to search • easy to transform to other formats • You can validatewhether your document is structure correct • important for business transaction document • prevent from error or miscommunication • An XML document is validif it has an associated document type declaration and if the document complies with the constraints expressed in it. • The document type declaration must appear before the first element in the document.
An XML with an External DTD flower1.xml <?xml version="1.0"?> <!DOCTYPE PLANT SYSTEM "flower.dtd"> <PLANT ZONE="3"> <COMMON>Columbine</COMMON> <BOTANICAL>Aquilegia canadensis</BOTANICAL> </PLANT> flower.dtd <?xml version="1.0"?> <!ELEMENT PLANT (COMMON, BOTANICAL)> <!ATTLIST PLANT ZONE CDATA #IMPLIED> <!ELEMENT COMMON (#PCDATA)> <!ELEMENT BOTANICAL (#PCDATA)>
XML 1.0 Recommendation • [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | PEReference | S)*']' S?)? '>' • [VC: Root Element Type] • [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment • [VC: Proper Declaration/PE Nesting] • [WFC: PEs in Internal Subset]
flower2.xml: Put DTD and XML in One File <?xml version="1.0"?> <!DOCTYPE PLANT [ <!ELEMENT PLANT (COMMON, BOTANICAL)> <!ATTLIST PLANT ZONE CDATA #IMPLIED> <!ELEMENT COMMON (#PCDATA)> <!ELEMENT BOTANICAL (#PCDATA)> ]> <PLANT ZONE="3"> <COMMON>Columbine</COMMON> <BOTANICAL>Aquilegia canadensis</BOTANICAL> </PLANT>
flower3.xml: Plant List <?xml version="1.0"?> <!DOCTYPE PLANTLIST [ <!ELEMENT PLANTLIST (PLANT+)> <!ELEMENT PLANT (COMMON, BOTANICAL)> <!ATTLIST PLANT ZONE CDATA #IMPLIED> <!ELEMENT COMMON (#PCDATA)> <!ELEMENT BOTANICAL (#PCDATA)> ]> <PLANTLIST> <PLANT ZONE="3"> <COMMON>Columbine</COMMON> <BOTANICAL>Aquilegia canadensis</BOTANICAL> </PLANT> <PLANT ZONE="2"> <COMMON>Cowslip</COMMON> <BOTANICAL>Clatha palustris</BOTANICAL> </PLANT> </PLANTLIST>
Well-Formed XML and Valid XML • Well-Formed XML: • A well-formed XML document does not necessarily include a DTD or a schema. • Valid XML: • XML that conforms to the vocabulary specified in a DTD or schema. • Document processing performance: • Well-formedness is an attribute of all XML documents • Well-formedness parsing is very fast • Validation can be time consuming and is specific to a particular application based on the DTY or Schema
XML- Schema and Data Type <Schema name="PLANTLIST" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schema-microsoft-com:datatypes"> <ElementType name="COMMON" content="textOnly"/> <ElementType name="BOTANICAL" content="textOnly"/> <AttributeType name="BESTSELLER" dt:type="enumeration" dt:values="yes no" default="no" /> <ElementType name="PLANT"> <element type="COMMON"/> <element type="BOTANICAL"/> <attribute type="BESTSELLER"/> </ElementType> <ElementType name="PLANTLIST" content="eltOnly" model="closed"> <element type="PLANT" minOccurs="1" maxOccurs="*" /> </ElementType> </Schema> flower_schema.xml
Style Language Contents of documents Style Language DSSSL SGML XML XSL HTML CSS XSL (Extensible Style Language) defines the specification for an XML document’s presentation and appearance. Standard: http://www.w3.org/TR/WD-xsl
XML Presentation: XSL • XML + XSL => HTML • Can be processed at either Server-Side or Client-Side XSL Stylesheet XML Documents XSL Processor HTML Browser course.xml HTML Documents <HTML> <BODY> <b>XML</b> class . . . </BODY> </HTML> <?xml version="1.0"?> <course> <name> XML </name> . . . </course>
Sample XSL and XML greeting.xml <?xml version="1.0" standalone="yes"?> <?xml-stylesheet href="greeting.xsl" type="text/xsl" ?> <greeting> Hello World! </greeting> greeting.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <H1> <xsl:value-of /> </H1> </xsl:template> </xsl:stylesheet>
XML and XSL XML deals only with the data structures and contents of a document XSL specifies rules to convert XML patterns to HTML tags and contents Client-Side XML XML Web server XML and XSL processor display Internet HTML (Browser) XSL Extensible Stylesheet Language (Browser-side add-on or building functions)
XSL • Transfer well-formed XML documents to HTML documents • Mapping<book_title>Harry Porter</book_title> <H1>Harry Porter</H1> • Add some data to user <book_author>Minder Chen<book_author> <H2>Author</H2><SPAN>Minder Chen</SPAN> • Hide some data from user
Integrating XML and XSL: product_xsl3.xml <?xml version='1.0'?> <?xml:stylesheet type="text/xsl" href="product_xsl3.xsl" ?> <PRODUCTLIST> <PRODUCT> <ID>html100</ID> <NAME>Introduction to HTML</NAME> <PRICE>$200</PRICE> </PRODUCT> <PRODUCT> <ID>xml100</ID> <NAME>Introduction to XML</NAME> <PRICE>$250</PRICE> </PRODUCT> </PRODUCTLIST>
XSL: for-each & value-of <?xml version="1.0"?> <HTML xmlns:xsl= "http://www.w3.org/TR/WD-xsl"> <BODY> <H1> Course Listing </H1> <xsl:for-each select="PRODUCTLIST/PRODUCT"> <xsl:value-of select="ID"/> : <b><xsl:value-of select="NAME"/></b> <br/> <i> Pirce: <xsl:value-of select="PRICE"/></i> <hr/> </xsl:for-each> </BODY> </HTML> Pattern: an XML document's target element Action: apply the style to the target element
Authoring Roles in XML Environments Domain Experts Document Type Definition (DTD) Presentation Authors Application Developers Content Providers Stylesheets Processing Applications XML Documents
XML Parsing • Parsing is the process of analyzing the structure of an XML document. • Parsing can be done on either client-side or server-side. • There are nonvalidating parsers and validating parsers. • Two popular API for XML parsing mechanisms are: • DOM: Document Object Model • SAX: Simple API for XML
Client-Side XML Parsing Using JavaScript XML Loading XML Document IE 5.0 HTML XML Object Model JavaScript Code XML Parser (msxml) • Dynamic HTML • Container: • <DIV ID="X"></DIV> • <SPAN ID="Y"></SPAN> XML Tags & Data
DOM <TABLE> <TBODY> <TR> <TD>Shady Grove</TD> <TD>Aeolian</TD> </TR> <TR> <TD>Over the River, Charlie</TD> <TD>Dorian</TD> </TR> </TBODY> </TABLE> • DOM specifies standard interface definitions for manipulating an XML document • DOM APIs are platform specific
mail.xml <?xml version="1.0" ?> <MEMO> <TO>Jodie</TO> <FROM>Bill</FROM> <CC>Philip</CC> <SUBJECT>My first XML document</SUBJECT> <BODY>Hello, World!</BODY> </MEMO>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript" FOR=window EVENT=onload> loadDoc(); </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> var rootElem; var xmlDoc = new ActiveXObject("microsoft.xmldom"); xmlDoc.load("mail.xml"); function loadDoc() { if (xmlDoc.readyState == "4") start(); else window.setTimeout("loadDoc()", 4000) } function start() { rootElem = xmlDoc.documentElement; todata.innerText =rootElem.childNodes.item(0).text; fromdata.innerText=rootElem.childNodes.item(1).text; ccdata.innerText=rootElem.childNodes.item(2).text; subjectdata.innerText=rootElem.childNodes.item(3).text; bodydata.innerText=rootElem.childNodes.item(4).text; } </SCRIPT> <TITLE>Code Listing 2-2</TITLE> </HEAD> mail.htm
Continued... <BODY> <DIV ID="to" STYLE="font-weight:bold;font-size:16"> To: <SPAN ID="todata" STYLE="font-weight:normal"></SPAN> </DIV> <BR> <DIV ID="from" STYLE="font-weight:bold;font-size:16"> From: <SPAN ID="fromdata" STYLE="font-weight:normal"></SPAN> </DIV> <BR> <DIV ID="cc" STYLE="font-weight:bold;font-size:16"> Cc: <SPAN ID="ccdata" STYLE="font-weight:normal"></SPAN> </DIV> <BR> <DIV ID="subject" STYLE="font-weight:bold;font-size:16"> Subject: <SPAN ID="subjectdata" STYLE="font-weight:normal"></SPAN> </DIV> <BR> <HR> <SPAN ID="bodydata" STYLE="font-weight:normal"></SPAN> </BODY> </HTML>
Server-Side XML Processing ASP File ASP File XML XML SERVER NETWORK CLIENT Passed over network as XML Display using client-side data binding Data extracted from database Updates original data source Database Client Application IE5 Browser XML Parser Updates only marshaled into XML by browser ASP file uses server-side parser to extract data
Server-side XML & XSL Processing • Advantages: Browser independent; client only requires HTML support Servlet or Server-side scripting http://java.sun.com/xml/