AppML - 使用 XML



AppML 應用程式可以用 xml 檔案讀取資料。下面是一個示例。

步驟 1:建立資料

第一步是建立一個基於 xml 的資料檔案,它將嚮應用程式 UI 中顯示的記錄提供資料。建立一個 students-records.xml

students_records.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<STUDENTS>
<STUDENT>
   <NAME>Ramesh</NAME>
   <CLASS>12</CLASS>
   <SECTION>White</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Suresh</NAME>
   <CLASS>12</CLASS>
   <SECTION>Red</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Mohan</NAME>
   <CLASS>12</CLASS>
   <SECTION>Red</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Robert</NAME>
   <CLASS>12</CLASS>
   <SECTION>Red</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Julie</NAME>
   <CLASS>12</CLASS>
   <SECTION>White</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Ali</NAME>
   <CLASS>12</CLASS>
   <SECTION>White</SECTION>
</STUDENT>
<STUDENT>
   <NAME>Harjeet</NAME>
   <CLASS>12</CLASS>
   <SECTION>White</SECTION>
</STUDENT>
</STUDENTS>

步驟 2:建立模型

建立 student_model.js 檔案,它將充當模型來描述記錄。

{
   "rowsperpage" : 7,
      "data" : {
      "type" : "xmlfile",
      "filename" : "students_records.xml",
      "record" : "STUDENT",
      "items" : [
         {"name" : "studentName", "nodename" : "NAME"},
         {"name" : "class", "nodename" : "CLASS"},
         {"name" : "section", "nodename" : "SECTION"}
      ]
   }
}

student_application.html

<!DOCTYPE html>
<html lang="en-US">
   <title>Students</title>
   <style>	  
      table {
         border-collapse: collapse;
         width: 100%;
      }

      th, td {
         text-align: left;
         padding: 8px;
      }

      tr:nth-child(even) {background-color: #f2f2f2;}
   </style>
   <script src="https://w3schools.tw/appml/2.0.3/appml.js"></script>
<body>
   <table appml-data="appml.php?model=students_model">
      <tr>
         <th>Student</th>
         <th>Class</th>
         <th>Section</th>
      </tr>
      <tr appml-repeat="records">
         <td>{{studentName}}</td>
         <td>{{class}}</td>
         <td>{{section}}</td>
      </tr>
   </table>
</body>
</html>

輸出

在 Web 伺服器上部署應用程式並訪問 html 頁面。驗證輸出。

first example
appml_data.htm
廣告
© . All rights reserved.