DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML基礎 >> 將HTML表單數據存儲為XML格式(2)
將HTML表單數據存儲為XML格式(2)
編輯:XML基礎     

 

文檔被存檔之後,如果你再打開這個文檔,那麼則會以如下代碼列表形式出現:
  
  MyXMLDoc.xml:
  
  <?xml version="1.0"?>
  <rootElement>
  <childElement1 />
  <childElement2 />
  </rootElement>
  
    在"MyXMLDoc.xml"文檔中,childElement1 和 childElement2 會以空的elements形式出現。如果它們被賦值,那麼每個值都將由標記符括起來。
  
    現在,讓我們來思考一下如何將HTML數據寫到XML文檔中去。我們已經知道該如何創建和存儲XML文檔。將一個表單數據寫到XML文檔中去的過程,現在已演變成為Request Object"s Form Collection以及將每一個表單域的value書定到XML element value 中去的步驟重復。以上可以通過ASP來完成。
  
  例:將數據輸送到XML
  
    現在,我們舉一個普通的HTML表單的例子來說明。此Form有用戶名,地址,電話,以及E-MAIL等幾個域。並將這些信息寫入XML文件中並保存。
  
  EnterContact.html:
  <html>
  <head>
  <title>
  Contact Information
  </title>
  </head>
  <body>
  <form action="processForm.asp" method="post">
  
  <h3>請輸入你的聯系方式</h3>
  First Name: <input type="text" id="firstName" name="firstName"><br>
  Last Name: <input type="text" id="lastName" name="lastName"><br>
  Address #1: <input type="text" id="address1" name="address1"><br>
  Address #2: <input type="text" id="address2" name="address2"><br>
  Phone Number: <input type="text" id="phone" name="phone"><br>
  E-Mail: <input type="text" id="email" name="email"><br>
  <input type="submit" id="btnSub" name="btnSub" value="Submit"><br>
  </form>
  </body>
  </html>
  
    將Form 中數據發送到processForm.asp.。這是一個ASP頁面,在這個ASP中將反復調用同一個函數將form數據寫入XML文件。
  
  processForm.asp:
  
  <%
  "--------------------------------------------------------------------
  "The "ConvertFormtoXML" Function accepts to parameters.
  "strXMLFilePath - The physical path where the XML file will be saved.
  "strFileName - The name of the XML file that will be saved.
  "--------------------------------------------------------------------
  
  Function ConvertFormtoXML(strXMLFilePath, strFileName)
  
  "Declare local variables.
  
  Dim objDom
  Dim objRoot
  Dim objField
  Dim objFieldValue
  Dim objattID
  Dim objattTabOrder
  Dim objPI
  Dim x

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved