什麼是AppML?
AppML是將服務器上的數據為HTML應用程序的工具。
w3data.php是AppML的子集。
w3data.php的目的是提供一種w3data.js與從Web服務器的數據。
應用程序模型
AppML使用應用程序模型 (用JavaScript對象符號)來描述服務器應用程序。
這個簡單的模型描述了從數據庫中檢索數據的完整的應用程序:
model_customers.js
{
"database" : {
"connection" : "localmysql",
"sql" : "SELECT * FROM Customers"}
}
該模型存儲在服務器上,並且不能由網絡用戶進行編輯。
你必須是一個服務器管理員或賦予的權利在服務器上編輯文件的用戶。
使用應用程序的模型很容易,只需添加的型號名稱,當你調用w3Http()來w3data.php:
例
<script>
w3Http("w3data.php?model=model_customers", function () {
if (this.readyState == 4 && this.status == 200) {
var myObject = JSON.parse(this.responseText);
w3DisplayData("id01", myObject);
}
});
</script>
試一試» 顯示從文本文件
例
<script>
w3Http("w3data.php?model=model_cd_from_txt", function () {
if (this.readyState == 4 && this.status == 200) {
var myObject = JSON.parse(this.responseText);
w3DisplayData("id01", myObject);
}
});
</script>
試一試» 這是在應用程序中使用的模型:
model_cd_from_txt
{
"data" : {
"type" : "csvfile",
"filename" : "cd_catalog.txt",
"items" : [
{"name" : "title", "index"
: 1},
{"name" : "artist", "index" :
2},
{"name" : "price", "index" : 5}
]
}
}
這是逗號分隔的文本文件:
cd_catalog.txt
Empire Burlesque,Bob Dylan,USA,Columbia,10.90,1985
Hide your heart,Bonnie Tyler,UK,CBS Records,9.90,1988
Greatest Hits,Dolly Parton,USA,RCA,9.90,1982
Still got the blues,Gary Moore,UK,Virgin records,10.20,1990
Eros,Eros Ramazzotti,EU,BMG,9.90,1997
One night only,Bee Gees,UK,Polydor,10.90,1998
Sylvias Mother,Dr.Hook,UK,CBS,8.10,1973
Maggie May,Rod Stewart,UK,Pickwick,8.50,1990
顯示從JSON文件
例
<script>
w3Http("w3data.php?model=model_cd_from_json", function () {
if (this.readyState == 4 && this.status == 200) {
var myObject = JSON.parse(this.responseText);
w3DisplayData("id01", myObject);
}
});
</script>
試一試» 這是在應用程序中使用的模型:
model_cd_from_json.js
{
"data" : {
"type" : "jsonfile",
"filename" : "cd_catalog.js",
"record" : "cd"
"items" : [
{"name" : "title", "nodename"
: "title"},
{"name" : "artist", "nodename" :
"title"},
{"name" : "price", "nodename" :
"title"}
]
}
}
這是JSON文件:
cd_catalog.js
{
"cd" : [
{ "title" : "Empire Burlesque",
"artist" : "Bob Dylan", "price" : "10.90" },
{ "title" :
"Hide your heart", "artist" : "Bonnie Tyler", "price" : "9.90" },
{ "title" : "Greatest Hits", "artist" : "Dolly Parton", "price" : "9.90" },
{ "title" : "Still got the blues", "artist" : "Gary Moore", "price" : "10.20"
},
{ "title" : "Eros", "artist" : "Eros Ramazzotti",
"price" : "9.90" },
{ "title" : "One night only",
"artist" : "Bee Gees", "price" : "10.90" },
{ "title" : "Sylvias
Mother", "artist" : "Dr.Hook", "price" : "8.10" }
]
}
顯示從XML文件
例
<script>
w3Http("w3data.php?model=model_cd_from_xml", function () {
if (this.readyState == 4 && this.status == 200) {
var myObject = JSON.parse(this.responseText);
w3DisplayData("id01", myObject);
}
});
</script>
試一試» 這是在應用程序中使用的模型:
model_cd_from_xml
{
"data" : {
"type" : "xmlfile",
"filename" : "cd_catalog.xml",
"record" : "CD",
"items" : [
{"name" : "artist", "nodename"
: "ARTIST"},
{"name" : "title", "nodename"
: "TITLE"},
{"name" : "country", "nodename"
: "COUNTRY"}
]
}
}
t這XML文件:
cd_catalog.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<PUBLISHED>1985</PUBLISHED>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS
Records</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1988</PUBLISHED>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1982</PUBLISHED>
</CD>
<CD>
<TITLE>Still got the
blues</TITLE>
<ARTIST>Gary Moore</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin records</COMPANY>
<PRICE>10.20</PRICE>
<PUBLISHED>1990</PUBLISHED>
</CD>
<CD>
<TITLE>Eros</TITLE>
<ARTIST>Eros Ramazzotti</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>BMG</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1997</PUBLISHED>
</CD>
<CD>
<TITLE>One night only</TITLE>
<ARTIST>Bee Gees</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>10.90</PRICE>
<PUBLISHED>1998</PUBLISHED>
</CD>
<CD>
<TITLE>Sylvias Mother</TITLE>
<ARTIST>Dr.Hook</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS</COMPANY>
<PRICE>8.10</PRICE>
<PUBLISHED>1973</PUBLISHED>
</CD>
</CATALOG>