六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

用XSL.ASP編輯XML文檔

[摘要]簡介  本文是"保存至HTML 表格數據至XML"的姐妹篇。如果你沒讀過上文,我建議您最好先瀏覽一下。本文是建立在上文基礎之上的。關于上文的舉例,讀者不斷給予了肯定的回應,同樣的,很多人都想知道如何編輯XML數據。因此,我寫下了此文。  使用XSL狀態下:打開一個XML文件,確...
簡介

  本文是"保存至HTML 表格數據至XML"的姐妹篇。如果你沒讀過上文,我建議您最好先瀏覽一下。本文是建立在上文基礎之上的。關于上文的舉例,讀者不斷給予了肯定的回應,同樣的,很多人都想知道如何編輯XML數據。因此,我寫下了此文。

  使用XSL狀態下:打開一個XML文件,確定將對它進行編輯、傳送至HTML表單,并最終將傳送到瀏覽器。 此XML元素的值將會被設置成HTML輸入域的值。在這些必要的編輯后,則可將這些經處理的信息提交至服務器,XML文件同時也被更新。

  第一步LOAD你將會編輯并在瀏覽器以HTML表格形式出現的文件。在以下的舉例中,XML在服務器上的變化被我跳過了,在使用微軟的XMLDOM 目標下,XML文件是能被XSL文件轉化的。我們在此同樣可以用到這個技巧來轉化XML文件。

  XML File: contact.xml:
  <?xml version="1.0" ?>
  <contact>
   <field id="firstName" taborder="1">
    <field_value>Michael</field_value>
   </field>
   <field id="lastName" taborder="2">
    <field_value>Qualls</field_value>
   </field>
   <field id="address1" taborder="3">
    <field_value>202 East Haverbrook</field_value>
   </field>
   <field id="address2" taborder="4">
    <field_value>Oklahoma City, OK 73114</field_value>
   </field>
   <field id="phone" taborder="5">
    <field_value>4055551234</field_value>
   </field>
   <field id="email" taborder="6">
    <field_value>mqualls@vertiscope.com</field_value>
   </field>
  </contact>
  本文舉例用到的XML文件與 "保存HTML表格至XML"一文中的舉例一樣。因此你能夠更直觀的觀察到其中的關聯之處。

  XSL File: contact.xsl:

  <?xml version="1.0"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match="/">
  <html>
  <body>
   <form method="post" action="EditContact.asp">
   <h1>Edit Contact:</h1>
   <table border="1" cellpadding="2">
   <xsl:for-each select="contact/field">
   <tr>
    <td>
     <xsl:value-of select="@id"/>
    </td>
    <td>
     <input type="text">
     <xsl:attribute name="id">
     <xsl:value-of select="@id" />
     </xsl:attribute>
     <xsl:attribute name="name">
     <xsl:value-of select="@id" />
     </xsl:attribute>
     <xsl:attribute name="value">
     <xsl:value-of select="field_value" />
     </xsl:attribute>
     </input>
    </td>
    </tr>
    </xsl:for-each>
   </table>
   <input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />
   </form>
   </body>
   </html>
   </xsl:template>
   </xsl:stylesheet>
  這個XSL文件使用了for-each XSL元素,使之在XSL文件的元素中反復。

  由此根元素開始,每個XML"域"元素的"ID"被寫成了HTML文本域的"ID"和"NAME"。

  同樣,XML文件中"域值/FIELD_VALUE"元素的值也被寫成為每個HTML文本域中的"值/value"。最后的結果自然是HTML格式包含了來自XML文件中將會被編輯的值。

  我之所以把"ID"從XML文件中的"域"元素里提出來,并把它置于XSL文件中的HTML文本域中,是為了不至于混淆并且可以促進命名的連貫性。這樣的話,不太熟悉編碼知識的朋友也能分辨出哪個XML域配哪 個HTML域。

  通過使用上述兩個文件,我們已為開始編輯XML文件做好了充分準備。XSL文件將會傳輸XML文件以便能夠在瀏覽器上顯示。我們可以在終端機上做這個傳輸工作,但不是最好的解決方案。用ASP的話,我們可以在服務器上做這個傳輸工作。同樣的,我們可以在服務器上做XML文件的編輯工作。
例子:通過使用XSL,ASP來編輯XML

  編輯 Contact.asp 是一個比較普遍的現象。這兒有兩個功能在編輯ASP頁面中起了主要作用。第一個是loadXMLFile功能,它LOAD并傳輸XML文件使之顯示出來;第二個是 updateXML 功能,它適用于編輯 XML文件國。

  ASP File: EditContact.asp:

   <%
    '-----------------------------------------------------------
    '"loadXMLFile" 函數接受兩個參數.
    'strXMLFile - XML文件的路徑名和文件名.
    'strXSLFilee - XSL文件的路徑名和文件名.
    '-----------------------------------------------------------
    Function loadXMLFile(strXMLFile, strXSLFile)
     '本地變量

     Dim objXML Dim objXSL
     '初始化XMLDOM對象.

     set objXML = Server.CreateObject("Microsoft.XMLDOM")
     '關閉同步加載的文件.
     objXML.async = false

     '加載XML文件.

     objXML.load(strXMLFile)
     '初始化用于加載XSL文件的XMLDOM對象.
     set objXSL = Server.CreateObject("Microsoft.XMLDOM")
     'Turn off asyncronous file loading.
     objXSL.async = false 'Load the XSL file.
     objXSL.load(strXSLFile)
     'Use the "transformNode" method of the XMLDOM to apply the
      'XSL stylesheet to the XML document. Then the output is
     'written to the client.
     Response.Write(objXML.transformNode(objXSL))
    End Function
    '-----------------------------------------------------------
    'The "updateXML" Function accepts one parameter.
    'strXMLFile - The path and file name of the XML file.
    '-----------------------------------------------------------

   Function updateXML(strXMLFile)
    'Declare local variables.
    Dim objDom
    Dim objRoot
    Dim objField
    Dim x
    'Instantiate the XMLDOM Object.
    set objDOM = Server.CreateObject("Microsoft.XMLDOM")
    'Turn off asyncronous file loading.
    objDOM.async = false
    'Load the XML file.
    objDOM.load strXMLFile
    'Set the objRoot variable equal to the root element of the
    'XML file by calling the documentElement method of the
    'objDOM (XMLDOM) object.
    Set objRoot = objDom.documentElement
    'Iterate through the Form Collection and write the
    'submitted values to the XML file.
    For x = 1 to Request.Form.Count
    'Check see if "btn" is in the submitted value, if so,
    'it is a button and should be ignored.
    If instr(1,Request.Form.Key(x),"btn") = 0 Then
    'Set objField variable equal to a field_value element by
    'calling the selectSingleNode method of the objRoot
    '(documentElement) object. The SelectSingleNode method
    'accepts a string parameter for querying the XML document.
    'In this case, the current value of the key property of
    'the Form Collection is used to find the appropriate
    'field_value element (more on this later).
    
    Set objField = objRoot.selectSingleNode("field[@id='" & _ Request.Form.Key(x) & "']/field_value")
    'Set the text property of the objField (field_value)
    'element equal to the value of the current form field.
    objField.Text = Request.Form(x)
   End If
   Next
   'After the XML file has been edited, is must be saved.
   objDom.save strXMLFile
   'Release all of your object references.
   Set objDom = Nothing
   Set objRoot = Nothing
   Set objField = Nothing
   'Call the loadXMLFile method, passing in the newly edited
   'XML file and the updatedcontact.xsl style sheet. This will
   'allow the client to see the edited information. More on the
   'updatedcontact.xsl file later.
   loadXMLFile strXMLFile,
   server.MapPath("updatedcontact.xsl")
  End Function
   'Test to see if the form has been submitted. If it has,
   'update the XML file. If not, transform the XML file for
   'editing.
  If Request.Form("btnSubmit") = "" Then
   loadXMLFile server.MapPath("Contact.xml"), _ server.MapPath("contact.xsl")
  Else
   updateXML server.MapPath("Contact.xml")
  End If
  %>

  正如你所看到的一樣,ASP文件處理了整個XML文件更新的過程。如果表單已被提交,那么XML文件則會被打開并更新。如果表單沒有被提交,那么XML文件會由contact.xsl傳送至HTML格式,以便用戶自行編輯。詳見以下舉例:

  For x = 1 to Request.Form.Count
   If instr(1,Request.Form.Key(x),"btn") = 0 Then
    Set objField = objRoot.selectSingleNode("field[@id='" & _ Request.Form.Key(x) & "']/field_value")
    objField.Text = Request.Form(x)
   End If
  Next
 
  上述代碼是更新XML文件的代碼。SelectSingleNode 方法是關鍵。


  在上述舉例中,問句是"field[@id='"& request.form.key(x) & "']/field_value"。所詢問的是:要求做為 子域元素 的field_value element 包含一個"ID",此ID而且是與現有的Form Collection中的關鍵值相匹配。一旦獲得適當的節點,則可以更新文本屬性以便與Form Collection中的值相匹配。




主站蜘蛛池模板: 亚洲综合图色40p | 四虎精品8848ys一区二区 | 午夜福利123 | 日韩毛片在线 | 偷自视频区视频真实在线 | 亚欧免费视频 | 日本美女视频韩国视频网站免费 | 在线精品免费观看综合 | 日韩精品一区二区三区中文版 | 无人码一区二区三区视频 | 手机看片国产精品 | 日韩a级毛片免费视频 | 人人揉人人添人人捏人人看 | 青青热久免费精品视频网站 | 又粗又大又硬又爽的免费视频 | 亚洲欧美日韩在线2020 | 中文字幕日韩精品在线 | 色噜噜狠狠大色综合 | 宅男午夜视频在线观看 | 午夜在线精品不卡国产 | 在线亚洲自拍 | 亚洲综合色婷婷六月丁香 | 小情侣旅馆内无套啪啪 | 污视频在线免费观看 | 午夜小视频在线观看 | 速度与激情9全集免费观看 速度与激情9免费完整版高清 | 手机在线看片国产日韩生活片 | 日韩黄色录像 | 偷拍第一页| 四虎影院在线免费观看视频 | 影音先锋亚洲综合小说在线 | 人妖在线精品一区二区三区 | 亚洲一区在线视频 | 色噜噜狠狠狠狠色综合久 | 伊人免费视频网 | 日本一片免费观看高清完整 | 伊人影院综合 | 天天舔天天色 | 欧美一区中文字幕 | 中文天堂在线最新版在线www | 青青草 久久久 |