用XSL.ASP编辑XML文档(2)

2016-01-29 19:30 0 1 收藏

用XSL.ASP编辑XML文档(2),用XSL.ASP编辑XML文档(2)

【 tulaoshi.com - ASP 】

       例子:通过使用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 = obj

来源:https://www.tulaoshi.com/n/20160129/1509547.html

延伸阅读
标签: ASP
  五、建立显示XML数据的ASP文件(index.asp) 这个文件要实现的功能就是读取并显示XML数据,首先创建一个XML对像然后把XML读入内存中,利用DOM分离出我们所要的数据。 <% strSourceFile = Server.MapPath("/") & "\List.xml" '获取XML文件的路径这里根据你的虚拟目录不同而不同 Set objXML = Server.Create...
标签: Web开发
作者:马晓宁 xml(可扩展标记语言)看起来可能像某种w3c标准——现在没有什么实际影响,即使以后能派上用场,也是很久以后的事。但实际上,它现在已经得到了应用。所以,不要等到xml已被加进了你最喜爱的html编辑器中才开始使用它。它现在就可以解决各种内部问题和b2b系统问题。 在sparks.com,我们使用xml来标准化从java...
标签: Web开发
随着Internet的发展,越来越多的信息进入互联网,信息的交换、检索、保存及再利用等迫切的需求使HTML这种最常用的标记语言已越来越捉襟见肘。HTML将数据内容与表现融为一体,可修改性、数据可检索性差,而XML借鉴了HTML与数据库、程序语言的优点,将内容与表现分开,不仅使检索更为方便,更主要的是用户之间数据的交换更加方便,可重用性更...
标签: Web开发
通过使用XSL,您可以向XML文档添加显示信息。 使用XSL显示XML XSL是首选的XML样式表语言。 XSL远比CSS更加完善。使用XSL的方法之一是在浏览器显示XML文件之前,先把它转换为HTML,正如以下的这些例子演示的那样: 查看XML文件: ?xml version="1.0" encoding="ISO-8859-1" ? - !-- Edited with XML Spy v2007 (http://www.altova.com) ...
标签: Web开发
一、必须弄清楚最终需要的是什么 我们通过asp或其他动态编程语言,最终需要的是XML格式的数据,这点和XML数据所在的文件载体无关,它可以是实实在在的XML文件,比如:http://blog.cnd8.com/rss_1.xml 。也可以为asp文档,比如:http://school.cnd8.com/rss.asp?id=42 他们都是XML数据的体现,为了实现XML数据的动态,所以需要使...

经验教程

63

收藏

73
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部