如何使用AppML
本章節將通過以下4個簡單的步驟演示如何創建<AppML>的應用程序。
下一章將介紹如何下載<AppML>,並開始在你自己的電腦上開發Web應用程序。
1.創建模型(Model)
使用以下內容創建文件
<datasource>
<database>
<connection>Demo</connection>
<sql>SELECT CustomerName,ContactName,City,Country FROM Customers</sql>
<orderby>CustomerName</orderby>
</database>
</datasource>
<filters>
<query>
<field>CustomerName</field>
</query>
</filters>
</appml>
在子目錄中Models(我們建議)將該文件保存為Customers.xml。
模型解析
<appml> 標籤定義了模型。
<datasource>標籤定義模型的數據源。
<database>標籤定義數據庫。
<connection>標籤定義數據庫的鏈接。
<sql>標籤定義數據查詢
<orderby>標籤定義默認排序。
<query>標籤定義合法的查詢過濾器。
2. 創建WEB 頁面
在第一個<AppML> app中,創建一個HTML頁面:
實例
<html>
<body>
<h1>My First Web Application</h1>
<table>
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Berlin</td>
<td>Germany</td>
</tr>
</table>
</body>
</html>
嘗試一下»
3. 添加樣式
在你的web頁面中添加層疊樣式在執行e <AppML> app:
實例
<html>
<head>
<link rel="stylesheet" href="appml.css">
</head>
<body>
<h1>My First Web Application</h1>
<table class="appmltable" >
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Berlin</td>
<td>Germany</td>
</tr>
</table>
</body>
</html>
嘗試一下»
4. 添加腳本, 然後執行應用
在你的web頁面中添加腳本來運行<AppML> app:
實例
<html>
<head>
<link rel="stylesheet" href="appml.css">
</head>
<body>
<h1>My First Web Application</h1>
<div id="Place01">
<table id="Template01" class="appmltable">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr id="appml_row" >
<td> #CustomerName# </td>
<td> #City# </td>
<td> #Country# </td>
</tr>
</table>
</div>
<script src="appml.js"></script>
<script>
app=new AppML("appml.htmlx","Models/Customers.xml");
app.run("Place01","Template01");
</script>
</body>
</html>
嘗試一下»
實例解析
<AppML> 庫中含有大量的函數。 這些函數可以再你的web頁面中調用。
<script src="appml.js">加載了<AppML>庫。
JavaScript語句: app=new AppML("appml.htmlx","Models/Customers.xml");創建AppML應用對象,然後執行web服務端腳本"appml.htmlx"來加載"Customers.xml"文件的數據。
JavaScript語句app.run("Place01","Template01");將數據插入到id="Place01"的HTML元素中,使用id="Template01"屬性元素作為模板。
屬性id="appml_row"定義了每條數據插入到HTML元素中。
# 標記中的數據會使用模型的數據替換。
以上所有,你可以想像到更快的原型嗎?
它是如何工作的?
- 當web頁面加載時, 你可以再頁面中加載<AppML> 控制器。
- 使用<AppML> 控制器, 你可以再頁面創建<AppML> 對象。
- 當你在頁面中運行<AppML> 對象, 它會請求服務端數據控制器。
- <AppML> 對像從服務器接收數據(使用數據模型)。
- <AppML> 對象(或者你的代碼) 在頁面中顯示數據。
- (可選) web用戶可以改變數據。
- (可選) <AppML> 可以在服務器後台發送數據。
- (可選) 服務器控制器可以在服務端存儲數據。
典型的Web 文件和文件夾:
數據文件夾: Data 圖片文件夾: Images 模型文件夾: Models 應用: Demo.htm 樣式: Demo.css <AppML>配置文件: appml_config.php (或者.htmlx) <AppML>樣式文件: appml.css <AppML>瀏覽器控制器: appml.js <AppML>服務器控制器: appml.php (or .htmlx) |
沒有限制
可以將<AppML> 對象放在HTML 頁面。 <AppML> 不影響頁面的其他部分。
<AppML> 在方案頁面不存在時默認為標準的顯示頁面。 這是完美的快速原型。
但是<AppML> 主要功能不是用於頁面的顯示。 <AppML> 主要是讀取應用程序數據. 它帶來的數據可以通過自由的使用HTML, CSS, 和JavaScript 來設計它們的顯示效果。 你可以:
- 自己編寫HTML,讓AppML處理數據。
- 調用模型,並處理所有的顯示。
- 使用AppML的屬性和方法,創建其它的組合。
你很快會發現<AppML>具備了強大的功能,它可以為你的web應用提供數據和數據模型。 你可以:
- 為用戶或用戶組定義數據安全
- 連接所有類型數據庫, 如Access, MySQL, SQL, 和Oracle
- 連接XML 文件和Text 文件
- 定義數據類型,數據格式,數據限制。
- 給模型添加任何新元素。