320 likes | 327 Views
Learn about XML, a universal standard for data exchange, and its integration in e-commerce. Explore topics like authoring XML, XML schema, XSL transformation, XML tools, and enabled standards. Discover XML's role in B2B transactions and structure of XML documents.
E N D
IEEM 5352E-Enterprise Integration eXtensible Markup Language (XML)
What is XML? • XML: eXtensible Markup Language (XML) defines an universal standard for electronically exchanging data for the Internet and Web applications and is supported by major IT vendors. Topics covered include: • Authoring XML element and documents • XML schema and Document Type Definition (DTD) • XSL (eXtensible Style Language) for transforming XML to HTML • Tools for authoring and browsing XML to document • XML 是在網際網路及Web上定義資料標準格式之語言。 XML是將傳統的SGML加以簡化,但是又比HTML有彈性,使用者可自行定義標籤 (Tags), 用來傳輸有結構性的資料是HTML之後方興未艾的Web標準。在電子商務上,尤其企業間(B2B) 電子商務交易,XML將式資料交換企業整合的重要技術與標準。
XML can take large chunks of information and consolidate them into an XML document - meaningful pieces that providestructure and organization to the information.
Basic building block of an XML document is the element defined bytags.
XML Documents • An well formed XML document can be read and understood by an XML parser. • DTD (Document Type Definition) determines the structure and elements of an XML document. • XML parsers read XML documents and xtract the data for access by another program.
EXL-Enabled Standards • RosettaNet is a consortium of product vendors and end users that defines a framework for data and process interchange with e-business -XML document and standard process flows. • XEDI is published specification describing how to map traditional EDI to XML and back again. • BizTalk is an industry consortium founded by Microsoft to define a standard XML grammar for XML-based messaging and metadata.
EXL-Enabled Standards (cont.) • XFRML is an XML standard for reporting financial information over the Internet. • XML-Schema is a working group of the W3C that is looking to describe a better mechanism for determining the structure of an XML document. • XML Query is another W3C working group looking to create a common set of operations and language syntax for accessing persisted XML data. • XSLT provides a standard XML document transformation mechanism using a stylesheet as a common processing engine.
XML Tools • 編輯XML檔案 • XML Notepad • XML Parser • 編輯 Cascading Style Sheet (CSS) • XML連結 CSS 呈現在 HTML 上的工具
XML範例 (prods.xml) <?xml version=“1.0”?> <PRODUCTLIST xmlns=“x-schems:listschema.xml”> <PRODUCT> <ID>722</ID> <NAME>PENTIUM 100</NAME> <PRICE>1000</PRICE></PRODUCT> <PRODUCT> <ID>721</ID> <NAME>PENTIUM 11 300<NAME> <PRICE>5000</PRICE></PRODUCT> <PRODUCT> <ID>720</ID> <NAME>PENTIUM 111 450</NAME> <PRICE>15000</PRICE> </PRODUCT> </PRODUCTLIST>
Rules for Well-Formed XML • Mandatory Closing Tag • The set of tags are unlimited but all container tags must have end tag, e.g., <tag>…</tag>. • Example: • <number>kj9876_34</number> • <due>1/12/98</due> • <bill_to>MTB1</bill_to> • <ship_to>MTO1</ship_to> • <selling_party>AC987</selling_party>
Rules for Well-Formed XML (cont.) • Proper Element Nesting • All tags must be nested correctly. Like HTML, XML can intermix tag, but tags may not overlap each other. • Legal XML <PRODUCT> <ID>721</ID> <NAME>PENTIUM 11 300</NAME> <PRICE>5000</PRICE> </PRODUCT> Illegal XML <PRODUCT> <ID> <NAME>PENTIUM 11 300<NAME> <PRICE>5000</PRICE> </PRODUCT> </ID>
Rules for Well-Formed XML (cont. 2) • Double-quote value delimiters • All attribute values must be enclosed in single or double quotation marks. • Legal: • <tag attribute=“value”> • Illegal: • <font size = 6> <XML> <xml> are different
Rules for Well-Formed XML (cont. 3) • Single tag element • Singleton tag (called empty element or tags without content) must be written in an abbreviated form using special XML syntax. • Legal: • <BR/> • <TITLE></TITLE> is equivalent to <TITLE/>
XML with an internal DTD DTD (Baseball.dtd) <!ELEMENT BASEBALL (TEAM)+> <!ELEMENT TEAM (CITY, PLAYER*)> <!ELEMENT CITY (#PCDATA)> <!ELEMENT PLAYER (LASTNAME, FIRSTNAME, AVG)> <!ELEMENT FIRSTNAME (#PCDATA)> <!ELEMENT LASTNAME (#PCDATA)> <!ELEMENT AVG (#PCDATA)> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE BASEBALL SYSTEM "Baseball.dtd"> <BASEBALL> <TEAM> <CITY>New York</CITY> <PLAYER> <LASTNAME>Strawberry</LASTNAME> <FIRSTNAME>Daryl</FIRSTNAME> <AVG>.286</AVG> </PLAYER> </TEAM> <TEAM> <CITY>Baltimore</CITY> <PLAYER> <LASTNAME>Alomar</LASTNAME> <FIRSTNAME>Roberto</FIRSTNAME> <AVG>.287</AVG> </PLAYER> </TEAM> </BASEBALL> +: 1 or more *: 0, 1 or more
XML 之網頁呈現 DTD/ XML Schema Structure Processing for Display or Conversion Document with Special Format (HTML/CSS) XML document content XSL Display XML Parser
XML Parser SERVER NETWORK CLIENT XML PARSER Client Application XML Converter Client Application Database XML
XML SCHEMA • XML SCHEMA (XML-DATA) • Much richer and more extensible way • Describe the rule for the content of a document and use XML itself as a grammar • It was submitted to the W3C as the XML-DATA submission
XML SCHEMA • A schema is defined using a particular XML syntax • <ElementType name="to" content="textOnly" /> • <ElementType name="from" content="textOnly" /> • <ElementType name="cc" content="textOnly" /> • <ElementType name="bcc" content="mixed"> • <attribute type="hidden" required="yes" /> • </ElementType> • <element type="to" minOccurs="1" maxOccurs="*" /> • <element type="from" minOccurs="1" maxOccurs="1" /> • <element type="cc" minOccurs="0" maxOccurs="*" /> • <element type="bcc" minOccurs="0" maxOccurs="*" /> Multiple
XML and XSL XML XML HTML Internet Web Server XSL (Browser) eXtensible Stylesheet Language (XSL)
XSL範例 <?xml version=“1.0”?> <HTML xmlns:xsl=“http:www.w3.org/tr/wd-xsl”> <body> <h1>test</h1> <xsl:for-each select=“PRODUUCTLIST/PRODUCT”> <DIV STYLE=“background-color:teal;color:white;padding:4px”> <SPAN STYLE=“font-weight:bold;color:white”> <xsl:value-of select=“id”/></SPAN> <xsl:value-of select=“name”/> </DIV> <DIV STYLE=“margin-left:20px;margin-bottom:font-size:12pt”> <I>price:<xsl:value-of select=“price”/></I> </DIV> <xsl:for-each> </body> </HTML>
XSL元素清單 • 應用模式 • Xsl: apply-templates • Xsl: stylesheet • Xsl: template • 取值 • Xsl: value of select
建立XML文件查詢 • Xsl: if • Xsl: when • Xsl: choose • Xsl: otherwise • Xsl: for-each
Business to Customer Order this book Web Server Bookstore Database Bookstore Customer Index all book Search Order books Book List Publish publisher Publisher XML
XML在Web上的呈現 • 在HTML中內嵌Java script • 僅load XML檔案,運用較複雜的程式作法抓取所需要的資訊 • 同時load XML跟XSL,script僅作讀檔的動作將呈現方式交給XSL處理 • 直接以XML呈現 • 在XML資料文件中做宣告所要參照的schema跟XSL(在不牽涉到html時,可這樣做)
HTML中內嵌 Java Script 協助執行結果 <script LANGUAGE="JavaScript" FOR="window" EVENT="onload"> var source = new ActiveXObject("Microsoft.XMLDOM"); source.load("2.xml"); var style = new ActiveXObject("Microsoft.XMLDOM"); style.load(“2.xsl”); document.all.item("dataContainer").innerHTML = source.transformNode(style.documentElement); </script> <div ID="dataContainer"></div> 運用script將兩個檔案Load進來 XML經過XSL抓取要呈現網頁的資料放置在datacontainer中
直接以XML呈現 <?xml-stylesheet type="text/xsl" href="2.xsl"?> <em:email xmlns:em="x-schema:1.xml" language="Western" encrypted="128" priority="HIGH"> 告知以文字格式呈現而參照的xsl檔案為2.xsl 在XML中參照的xml schema為1.xml
References • XML的入門與應用 • http://www.hpdiy.com.tw/xml.htm • 實戰XML • http://www.softchina.com.tw • XML IE5 • http://webdev.wrox.co.uk/books/1576/ • XML-Data standard • http://www.w3.org/TR/NOTE-XML-data/ • XSL standard • http://www.w3.org/TR/NOTE-XML-data/
XML網站推薦 • IBM網站 • http://www.ibm.com/developer/xml/ • 微軟網站 • http://msdn.microsoft.com/xml/default.asp • Free XML software • http://www.stud.ifi.uio.no/~lmariusg/linker/XMLtools.html • http://www.stud.ifi.uio.no/~lmariusg/linker/xmltools/by-platform.html