eEI-XML 教學

24
eEI-XML 教教

description

eEI-XML 教學. Some rule of XML. All XML elements must have a closing tag Tove Tove XML tags are case sensitive This is incorrect This is correct All XML elements must be properly nested this is incorrect - PowerPoint PPT Presentation

Transcript of eEI-XML 教學

Page 1: eEI-XML  教學

eEI-XML 教學

Page 2: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

Some rule of XMLAll XML elements must have a closing tag

<to>Tove

<to>Tove</to>

XML tags are case sensitive <Message>This is incorrect</message>

<Message>This is correct</Message>

All XML elements must be properly nested <aaa><bbb>this is incorrect</aaa></bbb>

<aaa><bbb>this is correct</bbb></aaa>

Page 3: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

Some rule of XML All XML documents must have a root element

With XML, white space is preserved

<root> <child> <subchild>.....</subchild> </child></root>

Page 4: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

Some rule of XMLXML elements must follow these naming rules:

Names can contain letters, numbers, and other characters Names must not start with a number or punctuation

character Names must not start with the letters xml (or XML or

Xml ..) Names cannot contain spaces

Page 5: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

程式設計工具Microsoft Visual Studio 2005Microsoft Access 2003 (Office之後的版本,須另存成mdb 檔 )

Page 6: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

建立 Access資料庫

點擊兩下空白資料庫,新增一個資料庫

Page 7: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

資料庫設計 (新增資料表 )

點擊右鍵出現選單,選擇「檢視設計」後會跳出資料表名稱視窗,輸入名稱後點擊「確定」

點擊此按鈕建立新資料表

Page 8: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

資料庫設計 (定義資料表 )

輸入欄位名稱,定義資料類型

Page 9: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

資料庫設計 (資料表關聯設計 )

點擊「資料庫關聯圖」,設計資料庫關聯

Page 10: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統流程

Start

End

Page 11: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (登入 )

輸入使用者帳號密碼後,點擊「登入」

使用資料表Account

Page 12: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (產品清單 )

資料庫關聯:「產品種類」對應到資料表 Catalog內的 CataID欄位

Page 13: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (加入購物車 )

點擊連結,將產品加入購物車內

選擇好要加入購物車產品後,點擊「進入購物清單」

Page 14: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (訂購畫面 )

輸入購買數量及交貨日期後,點擊「 Buy」購買

Page 15: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (訂單明細 )

點擊 XML檢視,產出 XML資料交換格式

Page 16: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

輸入的訂單資料

Page 17: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統畫面 (XML資料格式 )

訂單編號使用者帳號使用者姓名訂購日期、交貨日期

購買產品清單

產品 1及產品2

訂單總金額交貨地址

聯絡電話

整張訂單範圍

Page 18: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統程式 (XML字串產生語法 ) private void AssembleXML(string orderid, string[] productid, string[] product, string[] unitprice, string[] quan, string totalprice, string postcode, string address, string tel, string ordertime, string shippingtime)

{

string xmlstring = string.Empty;

xmlstring = "<?xml version=\"1.0\" encoding=\"Big5\"?><Order><OrderID>" + orderid +

"</OrderID><CustomerAccount>" + Session["Account"].ToString() +

"</CustomerAccount><CustomerName>" + Session["AccountName"].ToString() +

"</CustomerName><OrderDate>" + ordertime +

"</OrderDate><ShippingDate>" + shippingtime +

"</ShippingDate><BuyingProductList>";

for (int i = 0; i < product.Length; i++)

{

xmlstring += "<Product><ProductID>" + productid[i] +

"</ProductID><ProductName>" + product[i] +

"</ProductName><UnitPrice>" + unitprice[i] +

"</UnitPrice><Quantity>" + quan[i] +

"</Quantity></Product>";

}

xmlstring += "</BuyingProductList><TotalPrice>" + totalprice +

"</TotalPrice><ShippingAddress>" + postcode + " " + address +

"</ShippingAddress><ContactTel>" + tel +

"</ContactTel></Order>";

}

Page 19: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

系統程式 (XML字串寫入檔案語法 )string xmlname = Session["Account"].ToString()+ "_" + orderid;

string strFilePath = HttpContext.Current.Server.MapPath("~/orderXML/" + xmlname + ".xml").ToString();

string strFile = xmlstring;

using (System.IO.FileStream fs = new System.IO.FileStream(strFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite))

{

using (System.IO.StreamWriter fileWrite = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding(950)))

{

fileWrite.Write(strFile);

fileWrite.Flush();

}

}

Page 20: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

讀取 XML檔

串聯 XSL 與HTML之頁面

XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(Server.MapPath("order.xsl"));transform.Transform(Server.MapPath("orderXML/Customer.xml"), Server.MapPath("a.html")); Response.WriteFile(Server.MapPath("a.html"));

Page 21: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

XSLT example<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<body>

<h2>My CD Collection</h2>

<table border="1">

<tr bgcolor="#9acd32">

<th align="left">Title</th>

<th align="left">Artist</th>

</tr>

<xsl:for-each select="catalog/cd">

<tr>

<td><xsl:value-of select="title"/></td>

<td><xsl:value-of select="artist"/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template></xsl:stylesheet>

XML <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . . </catalog>

Page 22: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

XSLT example

Page 23: eEI-XML  教學

企業運籌與電子化中心Enterprise Logistics

and E-Business Center

Homework

以每組為單位寫出一範例產出 XML檔解釋所產出的 XML檔內容使用 XSL讀取所產出的 XML檔並顯示

繳交日期: Income報告完

Page 24: eEI-XML  教學

THANK YOU!