国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 開發 > 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.一样。

  如以往一样,我推荐大家复制以上代码至你的 服务器上并运行。希望以上举例会对你有所帮助。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
超碰在线网址| www在线视频| 亚洲精品视频区| 国产二级c片l毛片| 日本在线观看网站| 国产精品视频一区二区免费不卡 | 欧美性猛交xxxx免费看久久| 四虎精品成人a在线观看| 夜夜嗨yeyeh| 黄色毛片在线观看| 伊人中文字幕在线| 91av资源在线| 豆国产97在线|亚洲| www.操.com| eeuss影院在线观看| 午夜不卡视频| 18成年在线观看| 中文字幕第一页在线| 豆国产97在线|亚洲| 精品一区二区三区在线观看l| 国产尤物视频| 久久一本精品| 国产高清视频在线观看| 国产精品久久在线| xxx国产精品| 开心丁香婷婷深爱五月| 国产在线视频精品视频免费看| 九九视频九九热| 国产视频福利| 福利视频网址导航| 永久免费av片在线观看全网站| h网站免费在线观看| 国产精品伦一区二区三区视频 | 成年人在线观看| 69国产精品视频| 国产一二三视频| 国产美女自拍视频| 国产精品一区在线看| 免费国产阿v视频在线观看| 国产午夜精品一区理论片| 国产中文第一页| 国产精品入口麻豆免费看| 中文字幕亚洲免费| 国产色婷婷在线| 精品久久av| 黄色一级片视频| 国产黄视频网站| sese在线视频| 国内精品一区视频| 久热国产在线| 国产精品99999| a视频在线观看| 国产成人综合美国十次| 97一区二区三区| 九九色在线观看| 夜夜操天天干| 国产人成网在线播放va免费| www.大网伊人| 欧美高清xxxx性| 开心婷婷激情| 天天爱天天做色综合| 免费观看久久久久| 色综合久久五月天| av网站在线播放| 亚洲一道本在线| av在线免费观看网| 日本电影在线观看| 黄污在线观看| 成视频年人免费看黄网站| 99re热在线观看| 超碰免费在线观看| 五月天丁香在线| 精精国产xxxx视频在线中文版| 2019中文字幕视频| 永久免费av网站| 久久国产综合视频| 国产人成高清视频观看| 91青青在线视频| 国产乱在线观看视频| 中文天堂av| 国产小黄视频| 国产裸舞福利在线视频合集| 国产三区视频在线观看| а√资源新版在线天堂| 麻豆精品不卡国产免费看| 18 激情视频在线| 国产免费电影网站入口| 在线观看的网站你懂的| 最新天堂资源在线| 国产专区在线| 免费a级毛片在线播放| 天天av天天爱| 波多野结衣久久高清免费| 国产精品久久久久永久免费看| 影音先锋中文字幕在线| 国产香蕉视频在线观看| 中文字幕国产视频| 最近中文字幕在线中文视频 | 99精品老司机免费视频| 日本中文字幕在线观看| 欧美日韩视频精品一区二区| 天海翼中文字幕| 日本福利在线| 国产一起色一起爱| 九九视频在线播放| 国产三级在线免费| av网站大全在线观看| 欧美日韩性视频一区二区三区| 久久av少妇| 91青青在线视频| 大香伊人中文字幕精品| 中中文字幕av在线| av手机免费观看| 国产一级免费在线观看| a级在线观看| 91极品在线| 中文字幕不卡免费视频| 国产精品777一区二区| 九九热在线视频免费观看| 国产二级片在线| 天堂在线视频| 国产尤物视频在线| 成年黄网站在线观看免费| 中文在线官网天堂| 精品视频三区| 在线视频观看亚洲| 国产素人视频在线观看| 国产在线色视频| 国产在线一二三| 国产精品一区在线看| 国自产拍在线网站网址视频| 免费精品国产自产拍观看| 超碰国产在线观看| 国产女人在线视频| 国产精品免费视频一区一| 在线观看中文| 最近中文字幕av免费高清| 青青在线视频| 一二三四区在线观看| 午夜在线不卡| 亚洲欧美日韩一区成人| 高清色视频在线观看| 91超碰在线免费| 91啦中文在线| 国产区视频在线| 国产天堂视频| 成人精品福利| 国产视频精选在线| 午夜视频在线观看网站午夜视频在线 | 99re热视频在线| 在线视频中文字幕久| 国产小视频免费在线观看| 五月婷婷在线观看| 国产午夜三区视频在线| 久久一本精品| 国产在线看片| 在线中文字幕av| 在线播放www| 在线一二三区| 在线91av| 69视频在线观看| 国产在线高潮| 在线观看免费高清完整| av一本在线| 欧美在线中文| 人人干人人插| 日本电影在线观看| 啪啪免费视频一区| 欧美aaa一级片| 九九色在线观看| 中文天堂av| 日本成人在线播放| 99综合精品久久| 中文乱码字幕高清在线观看| 国产羞羞视频在线播放| 亚洲人成电影| 激情五月色综合亚洲小说| 亚洲私人影吧| 九九热在线视频观看| 激情网站在线| www.香蕉视频在线观看| av在线网页| 69国产精品视频| 国产超碰97| 亚洲xxxxxx| 高清欧美精品xxxxx在线看| 伊人影院在线视频| 91xxx在线观看| 天堂中文在线观看| 午夜视频在线观看网站午夜视频在线| 国产视频中文字幕| 中文字幕一区二区三区免费视频| 国产精品亚洲色图| 青青青青在线| 久热免费视频| 久久国产热视频| 国产在线你懂得| 一本大道久久a久久精品| 五月婷婷视频在线观看| 在线三级中文|