精品秘无码一区二区三区老师-精品秘一区二三区免费雷安-精品蜜桃秘一区二区三区-精品蜜桃秘一区二区三区粉嫩-精品蜜桃一区二区三区-精品蜜臀国产aⅴ一区二区三区

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員
Please input your contact infomation here: 
 
 
 
 
 
 
 
 

ASP基礎:將HTML表單數據存儲為XML格式

admin
2010年8月19日 23:13 本文熱度 3733
如你熟知ASP,XML和HTML4。0,請讀下列示例
將表單數據存為XML格式
  通常的,ASP中表單提交的數據一般被寫入數據庫。然而,如果你想讓發送數據更為簡便易行,那么,可以將它書寫為XML文件格式。這種方式對于在web上收集的數據更為有用。因為XML對于所用平臺來說非常的簡便,所以用不著轉換數據格式。
  將提交的數據寫為XML文檔,則需要通過Microsoft XMLDOM Object創建一個新的XML文檔。Microsoft XMLDOM Object擁有一個可擴展對象庫,通過它可以創建elements,attributes以及values,通過創建的這些項目則可以組成XML文檔。我無法將整個目標模型做個完整的介紹,因為它所包含的內容太廣泛,對于將建成的網站來說,目標模型甚至通過自身也能組建一個相對完整的部份。
  在XMLDOM Object被創建出來之后,通過創建目標(此目標是關于組成XML文檔中每一層的ELEMENTS而言)XML的結構會被演示出來。接下來,會舉例說明XMLDOM是怎樣被創建出來的。創建root element之后,將它附加在XMLDOM文件上。然后創建child elements并附加在root element上,最后存儲文檔。

演示Microsoft XMLDOM 對象 

<% 
Dim objDom 
Dim objRoot 
Dim objChild1 
Dim objChild2 
Dim objPI 
 
" XMLDOM 對象使用Server對象的CreateObject方法創建 
Set objDom = Server.CreateObject("Microsoft.XMLDOM") 
"使用XMLDOM的createElemnet方法創建一個IXMLDOMElement對象。 
"createElemnet方法又一個string參數,這個string 表示該element的名稱。 
返回值被傳遞到objRoot變量。objRoot表示XML文檔的根元素.。 
 
Set objRoot = objDom.createElement("rootElement") 
 
"Use the appendChild Method of the XMLDOM Object to add the objRoot 
"Element Reference to the XML Document. 
 
objDom.appendChild objRoot 
 
"Now, following the same steps, you will create references to the 
"child elements for the XML Document. The only difference is, when the 
"child elements are appended to the document, you will call the 
"appendChild Method of the IXMLDOMElement Object rather than the 
"appendChild Method of the XMLDOM Object. By using the IXMLDOMElement 
"to append the children, you are differentiating (and applying tiered 
"structure to) the child elements from the root element. 
 
Set objChild1 = objDom.createElement("childElement1") 
objRoot.appendChild objChild1 
Set objChild1 = objDom.createElement("childElement2") 
objRoot.appendChild objChild2 
 
"The final step to take care of before saving this document is to add 
"an XML processing instruction. This is necessary so that XML parsers 
"will recognize this document as an XML document. 
 
Set objPI = objDom.createProcessingInstruction("xml","vertsion="1.0"") 
 
"Call the insertBefore Method of the XMLDOM Object in order to insert 
"the processing instruction before the root element (the zero element 
"in the XMLDOM childNodes Collection). 
 
objDom.insertBefore objPI, objDom.childNodes(0) 
 
"Calling the Save Method of the XMLDOM Object will save this XML 
"document to your disk drive. In this case, the document will be saved 
"to the "c:" drive and will be named "MyXMLDoc.xml". When saving an 
"XML document, if the file does not exist, it will be created. If it 
"does exist, it will be overwritten. 
 
objDom.Save "c:MyXMLDoc.xml" 
 
%> 

文檔被存檔之后,如果你再打開這個文檔,那么則會以如下代碼列表形式出現: 

MyXMLDoc.xml: 


 
 
 
 
 

  在"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: 

 
 
  <BR>Contact Information  <BR> 
 
 
 
 
First Name:
Last Name: 
Address #1: 
Address #2: 
Phone Number: 
E-Mail: 
 
 
 

  將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 
    ’Instantiate the Microsoft XMLDOM. 
    Set objDom = server.CreateObject("Microsoft.XMLDOM") 
    objDom.PreserveWhiteSpace = True 
    ’Create your root element and append it to the XML document. 
    Set objRoot = objDom.CreateElement("Contact") 
    objDom.AppendChild objRoot 
    ’Iterate through the Form Collection of the Request Object. 
    For x = 1 To Request.Form.Count 
    ’Check to see if "btn" is in the name of the form element. 
    ’If it is, then it is a button and we do not want to add it 
    ’to the XML document. 
        If Instr(1,Request.Form.Key(x),"btn") = 0 Then 
        ’Create an element, "field". 
            Set objField = objDom.CreateElement("Field") 
            ’Create an attribute, "ID". 
            Set objAttID = objDom.CreateAttribute("ID") 
            ’Set the value of the id attribute equal the the name of 
            ’the current form field. 
            objAttID.Text = Request.Form.Key(x) 
            ’The setAttributeNode method will append the id attribute 
            ’to the field element. 
            objField.SetAttributeNode objAttID 
            ’Create another attribute, "taborder". This just orders the 
            ’elements. 
            Set objattTabOrder = objDom.createAttribute("taborder") 
            ’Set the value of the taborder attribute. 
            objAttTabOrder.Text = x 
            ’Append the taborder attribute to the field element. 
            objField.SetAttributeNode objAttTabOrder 
            ’Create a new element, "field_value". 
            Set objFieldValue = objDom.CreateElement("FieldValue") 
            ’Set the value of the field_value element equal to 
            ’the value of the current field in the Form Collection. 
            objFieldValue.Text = Request.Form(x) 
            ’Append the field element as a child of the root element. 
            objRoot.AppendChild objField 
            ’Append the field_value element as a child of the field elemnt. 
            objField.AppendChild objFieldValue 
        End If 
    Next 
    ’Create the xml processing instruction. 
    Set objPI = objDom.CreateProcessingInstruction("xml", "version=""1.0""") 
    ’Append the processing instruction to the XML document. 
    objDom.InsertBefore objPI, objDom.ChildNodes(0) 
    ’Save the XML document. 
    objDom.Save strXMLFilePath & "" & strFileName 
    ’Release all of your object references. 
    Set objDom = Nothing 
    Set objRoot = Nothing 
    Set objField = Nothing 
    Set objFieldValue = Nothing 
    Set objAttID = Nothing 
    Set objAttTabOrder = Nothing 
    Set objPI = Nothing 
End Function 
’Do not break on an error. 
On Error Resume Next 
’Call the ConvertFormtoXML function, passing in the physical path to 
’save the file to and the name that you wish to use for the file. 
ConvertFormtoXML "F:\Asp\","Contact.xml" 
’Test to see if an error occurred, if so, let the user know. 
’Otherwise, tell the user that the operation was successful. 
If Err.Number <> 0 then 
    Response.Write("Errors occurred while saving your form submission.") 
Else 
    Response.Write("Your form submission has been saved.
Go Back") 
End If 
%> 

  如果你是在你自己的應用程序中使用以上代碼,請謹記一件事情,在"ConvertFormtoXML"函數已經運行的情況下,如果XML文件名已經存在,那么,文件將會被覆蓋。在此,我建議在使用"ConvertFormtoXML"功能前,最好用隨機建立的文件名。這樣,就將有價值數據被改寫的風險降為零。 
  關于XML文件的產生,舉例如下:

Contact.xml: 

 
 
 
     
        Dicky 
     
     
        Gu 
     
     
        ShangHai 
     
     
        BeiJing 
     
     
        123456 
     
     
        AppleBBS@GMail.Com 
     
 

  我在此建議:將以上代碼復制到你個人網站服務器上的同名頁面上,并運行以上示例時。請一定要明確你使用的是對你個人服務器有效的路徑和文件名。 
  當你一切準備好時,請再次檢驗你的XML文件。

該文章在 2010/8/19 23:13:56 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产成人aⅴ尤物国产 | 亚洲av无码成人yellow中文字幕福利在线久久亚洲锕无码人 | 国产成人精品一区二区3 | 国产精品亚洲综合一区在线观看 | 大片精品免费永久看NBA人人视频 | 麻豆高潮AV久久久久久久 | 自拍日韩亚洲 | 每日更新在线观看av | 成人无码av网 | 国产成人精品视频VA片 | 亚洲av无码乱码在线观看代蜜 | 日韩av美女人 | 亚洲国产精品自产在线播放 | 亚洲二区在线视频 | 日韩精品妓女在线观看网站视频 | 免费观看成人毛片A片2008 | 白莲花乖腿打开h调教 | 亚洲精品乱码久久久久中文字幕 | 97人妻无码一区二区精品免费 | 国产av一区二区三区 | 国产丰满肥熟在线观看 | 亚洲不卡无码av中文字幕 | b站影院永久免费是真的吗 b站影院永久入口vip | 亚洲系列中文字幕一区二区 | 亚洲天堂亚洲一区 | 国产精品久久久久久人妻精品动漫 | 性色av一区二区三区夜夜嗨 | 中文字幕aⅴ天堂在线 | 亚洲精品久久久久久久久久吃药 | 五月天狠狠爱婷婷丁香社区 | 亚洲欧美黑人深喉猛交群 | 国产女人18毛片水真多 | 久久精品无码一区二区日韩av | 免费的三片播放器 | 亚洲精品久久久久久久蜜桃臀 | 亚洲日本中文字幕区 | 午夜精品一区二区 | 亚洲秘无码一区二区三区蜜桃 | 亚洲av人无码激艳猛片服务器 | 动漫人妻h无码 | 伊人中文字幕波多野结衣 |