亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > XML > 正文

給XML文檔添加新 ”records”

2024-09-05 20:55:11
字體:
來源:轉載
供稿:網友

本文所举的例子与保存HTML格式数据至XML类似。在以往当表格被提交后,我们通常会创建一个新的文档,现在只要文档已经存在,那么直接添加就可以了。此种技术的使用与创建基本数据类似。

  在前面的文章里,我已经演示了如何使用XMLDOM。因此,我们可以直接进入本文的示例。

  我们需要考虑的第一件事是我们将用于添加新"记录"的HTML 表单。在"将HTML表单数据保存至XML"例子中我们已使用过此表单,只是更改了文件名,但代码是相同的。

  AddContact.html:

复制代码 代码如下:

  
  
    Contact Information 
  
  
   
 
   

Enter your contact information

 
   First Name: 
   
 Last Name: 
   
 Address #1: 
   
 Address #2: 
   
 Phone Number: 
   
 E-Mail: 
   
 
   
 
   

  
  

  我们设置此HTML表单是来处理ADD。ASP的。这里的ASP 页面具有检测XML.文件及ROLODEX.XML是否存在的功能。如果它们确实存在,ASP则会在文件上附加新的条目,如果文件不存在,则需要创建。 

  Process Add.asp: 
复制代码 代码如下:

     '--------------------------------------------------------------------
   'The "addNewContacttoXML" Function accepts two parameters.
   'strXMLFilePath - The physical path where the XML file will be saved.
   'strFileName - The name of the XML file that will be saved.
   '--------------------------------------------------------------------
   Function addNewContacttoXML(strXMLFilePath, strFileName) 
    'Declare local variables. 
    Dim objDom 
    Dim objRoot 
    Dim objRecord 
    Dim objField
    Dim objFieldValue 
    Dim objattID 
    Dim objattTabOrder 
    Dim objPI 
    Dim blnFileExists 
    Dim x 
    'Instantiate the Microsoft XMLDOM. 
    Set objDom = server.CreateObject("Microsoft.XMLDOM") 
    objDom.preserveWhiteSpace = True
    'Call the Load Method of the XMLDOM Object. The Load ethod has a 
    'boolean return value indicating whether or not the file could be 
    'loaded. If the file exists and loads it will return true, otherwise,
    'it will return false.

    blnFileExists = objDom.Load(strXMLFilePath & "/" & strFileName) 

    'Test to see if the file loaded successfully. 
    If blnFileExists = True Then 
     'If the file loaded set the objRoot Object equal to the root element 
     'of the XML document. 
     Set objRoot = objDom.documentElement Else 
     'Create your root element and append it to the XML document. 
     Set objRoot = objDom.createElement("rolodex") 
     objDom.appendChild objRoot
    End If 
     'Create the new container element for the new record. 
     Set objRecord = objDom.createElement("contact") 
     objRoot.appendChild objRecord 
     '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("field_value") 

       '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 new record container 
       'element, contact. objRecord.appendChild objField 
       'Append the field_value element as a child of the field element.
       objField.appendChild objFieldValue 
      End If 
     Next 

     'Check once again to see if the file loaded successfully. If it did 
     'not, that means we are creating a new document and need to be sure to 
     'insert the XML processing instruction. 

     If blnFileExists = False then 

      '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) 
     End If 

     'Save the XML document.

     objDom.save strXMLFilePath & "/" & strFileName 

     'Release all of your object references. 
     Set objDom = Nothing 

     Set objRoot = Nothing 
     Set objRecord = Nothing 
     Set objField = Nothing 
     Set objFieldValue = Nothing 
     Set objattID = Nothing 
     Set objattTabOrder = Nothing 
     Set objPI = NothingEnd 

    Function
    'Do not break on an error.

    On Error Resume Next

    'Call the addNewContacttoXML function, passing in the physical path to
    'save the file to and the name that you wish to use for the file.

    addNewContacttoXML "c:","rolodex.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.")
    End If
   %>

如果你已经读过关于"将HTML 表单数据保存至XML格式"的文章,你会注意到附加到将HTML数据扩展到XML文件的代码与HTML数据扩展到新文档的代码基本上是一致的。但是这里还是有两个主要的不同点:

   'Call the Load Method of the XMLDOM Object. The Load Method has a 
   'boolean return value indicating whether or not the file could be 
   'loaded. If the file exists and loads it will return true, otherwise, 
   'it will return false. 

   blnFileExists = objDom.Load(strXMLFilePath & "/" & strFileName) 
   
   'Test to see if the file loaded successfully. 

   If blnFileExists = True Then 

    'If the file loaded set the objRoot Object equal to the root element 
    'of the XML document. 

    Set objRoot = objDom.documentElement
   Else 

    'Create your root element and append it to the XML document. 
    Set objRoot = objDom.createElement("contact") 
    objDom.appendChild objRoot 
   End If

  本节的代码来自addNewContacttoXML 功能。因为我们不可能每次都新建一个文件,所以我们改为保存CONTACT。如果能够LOAD此文件呢,我们则获得了这个XML文档的根元素;如果不能够呢,那么我们就假设它不存在并创建一个新的要元素并将它附加到XML文档上。

  另外一个主要区别在于:当我们对文件进行二次检测,是否成功的LOAD,这样我们可以决定是否需要加上 一条处理指令。如果文件存在,我们就不需要加上这条指令。但是,如果创建了一个新的文件,那么则一定得加上这条处理指令。

  'Check once again to see if the file loaded successfully. If it did 
  'not, that means we are creating a new document and need to be sure to 
  'insert the XML processing instruction. 

  If blnFileExists = False then 

   '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) 
  End If

  除开以上两点不同之处外,你可以发现 保存数据至新文件的代码实际上是与 附加新record至存在文件的代码是一样的。我们创建一个新的element, contact CONTAINER,以便能容下每个新添的RECORD。代码将会在Form Collection of the Request Objec中不断重复以创建适合的XML节点并将这些节点值设置得与当前Form Field.一样。

  如以往一样,我推荐大家复制以上代码至你的 服务器上并运行。希望以上举例会对你有所帮助。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品久久久久999| 亚洲美女在线视频| 亚洲国产成人精品久久| 欧美日韩美女在线| 久久激情五月丁香伊人| 欧美电影免费观看高清完整| 在线观看精品国产视频| 亚洲一品av免费观看| 国产午夜精品一区理论片飘花| 色综合久久88| 中国日韩欧美久久久久久久久| 亚洲欧美日韩中文在线制服| 欧美成人免费全部观看天天性色| 日韩视频第一页| 久久亚洲国产精品| 91精品国产91久久久久久最新| 欧美肥老妇视频| 亚洲电影免费观看高清完整版| 96国产粉嫩美女| 久久久久久国产免费| 亚洲欧美日韩中文视频| 欧美激情亚洲综合一区| 国产成人亚洲综合青青| 亚洲国产97在线精品一区| 日韩av高清不卡| 国产自产女人91一区在线观看| 日韩av在线网| 久久免费视频网站| www.日韩.com| 久久久国产精品视频| 亚洲国产成人精品久久久国产成人一区| 亚洲成人久久电影| 亚洲va久久久噜噜噜久久天堂| 国产精品aaaa| 久久久久久久激情视频| 91精品久久久久久久久久久| 中文字幕在线精品| 一本色道久久88综合亚洲精品ⅰ| 一区二区三区四区在线观看视频| 久久免费视频网站| 欧美大片大片在线播放| 亚洲精品久久久久久久久久久久| 欧美日韩亚洲成人| 久久久久久午夜| 久久精品久久精品亚洲人| 久久香蕉精品香蕉| 亚洲自拍偷拍区| 一区二区三区视频在线| 国产亚洲欧美aaaa| 亚洲国产欧美精品| 亚洲国语精品自产拍在线观看| 国产精品视频公开费视频| 欧美激情精品久久久久久久变态| 亚洲人成人99网站| 国产欧美一区二区白浆黑人| 欧美日韩亚洲一区二区三区| 69精品小视频| 91精品国产自产在线| 日韩色av导航| 一本色道久久综合狠狠躁篇的优点| 九九热这里只有精品免费看| 黑人巨大精品欧美一区二区免费| 九九精品在线播放| 欧美性视频精品| 成人欧美一区二区三区黑人| 欧美成人激情在线| 久久99精品视频一区97| 日韩电影大片中文字幕| 国产欧美一区二区三区视频| 亚洲欧美国产高清va在线播| 国产亚洲精品91在线| 懂色aⅴ精品一区二区三区蜜月| 中文字幕亚洲无线码a| 欧美日韩亚洲精品一区二区三区| 亚洲欧美福利视频| 亚洲欧美日韩在线一区| 一区二区欧美日韩视频| 久久久www成人免费精品| 久久精品国产久精国产一老狼| 亚洲aa中文字幕| 精品国产一区二区三区在线观看| 九九精品在线视频| 日韩激情在线视频| 亚洲精品第一国产综合精品| 久久综合九色九九| 久久国产精品99国产精| 福利微拍一区二区| 91精品久久久久久久久中文字幕| 色妞久久福利网| 国产亚洲精品一区二555| 国产精品网址在线| 久久久人成影片一区二区三区观看| 国外成人在线视频| 久久久99久久精品女同性| 欧美野外wwwxxx| 久久免费精品视频| 欧美性猛交xxxxx免费看| 久久久人成影片一区二区三区观看| 另类专区欧美制服同性| 高跟丝袜欧美一区| 亚洲国产成人久久综合一区| 国产成人高清激情视频在线观看| 91久久精品日日躁夜夜躁国产| 欧美第一黄色网| 日韩亚洲一区二区| 欧美一区二三区| 欧美激情乱人伦一区| 免费不卡欧美自拍视频| 久久久女人电视剧免费播放下载| 久久久99免费视频| 高潮白浆女日韩av免费看| 欧美日韩另类视频| 成人午夜在线视频一区| 国产精品美女网站| 国产精品99久久久久久人| 91久久在线观看| 国产精品一区二区久久久久| 青青草一区二区| 在线电影中文日韩| 国内精品久久影院| 精品一区二区三区四区在线| 日韩中文有码在线视频| 日韩视频永久免费观看| 日韩中文字幕免费看| 国产一区二区美女视频| 国产成人精品一区二区| 亚洲97在线观看| 欧美夫妻性生活视频| 国产在线久久久| 国产精品成人观看视频国产奇米| 欧美日韩久久久久| 高清亚洲成在人网站天堂| 国产精品美女午夜av| 欧美性视频网站| 亚洲第一福利网站| 久久久久久国产精品久久| 欧美激情中文字幕在线| 中文字幕一区二区三区电影| 久久久成人精品| 精品亚洲国产成av人片传媒| 精品亚洲一区二区三区| 久久午夜a级毛片| 国产欧美一区二区三区久久人妖| 欧美超级免费视 在线| 国产日韩在线看片| 91老司机在线| 久久久最新网址| 亚洲女人天堂成人av在线| 欧美一级电影在线| yw.139尤物在线精品视频| 国产午夜精品麻豆| 亚洲精品久久久久中文字幕欢迎你| 国精产品一区一区三区有限在线| 日韩成人在线视频网站| 日韩欧美亚洲国产一区| 久久久久久香蕉网| 久久精品中文字幕免费mv| 亚洲成人在线网| 91禁外国网站| 国产成人亚洲综合青青| 久久av资源网站| 在线精品高清中文字幕| 亚洲国产精品一区二区三区| 欧美黑人极品猛少妇色xxxxx|