新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> XML网站展示,XML源代码,XML编程示例。 本版仅接受原创、转贴、网站展示,具体的技术交流请前往各相关版块。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XML源码及示例(仅原创和转载) 』 → vbs类生成xml文件 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5153 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: vbs类生成xml文件 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     小鞋子 帅哥哟,离线,有人找我吗?
      
      
      威望:6
      头衔:大法師
      等级:大二期末(Java考了96分!)
      文章:353
      积分:958
      门派:XML.ORG.CN
      注册:2003/12/19

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给小鞋子发送一个短消息 把小鞋子加入好友 查看小鞋子的个人资料 搜索小鞋子在『 XML源码及示例(仅原创和转载) 』的所有贴子 引用回复这个贴子 回复这个贴子 查看小鞋子的博客楼主
    发贴心情 vbs类生成xml文件

    有两文件:
    objXML.asp:测试文件
    clsXML.asp:vbs类文件
    代码:
    objXML.asp

    <%@ Language=VBScript %>
    <% Option Explicit %>
    <!--#INCLUDE FILE="clsXML.asp"-->
    <%
    Dim objXML, strPath, str
    Set objXML = New clsXML

    strPath = Server.MapPath(".") & "\New.xml"

    objXML.createFile strPath, "Root"
    'Or If using an existing XML file:
    'objXML.File = "C:\File.xml"

    objXML.createRootChild "Images"

    'Here only one attribute is added to the Images/Image Node
    objXML.createChildNodeWAttr "Images", "Image", "id", "1"
    objXML.updateField "Images//Image[@id=1]", "super.gif"
    objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _
    Array(24, 31, 30)
    objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _
    Array(24, 30, 29)
    objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _
    Array(24, 31, 85)

    'Notice that all three job nodes have size 24, all of those
    'nodes will be updated
    objXML.updateField "Jobs[@Size=24]", "24's"

    'Notice that only two nodes have the specified XPath, hence
    'only two new child nodes will be added
    objXML.createChildNodeWAttr "Jobs[@Size=24 and @Length=31]", "Specs", _
    Array("Wood", "Metal", "Color"), _
    Array("Cedar", "Aluminum", "Green")

    'It is always important to iterate through all of the nodes
    'returned by this XPath query.
    For Each str In objXML.getField("Jobs[@Size=24]")
    Response.Write(str & "<br>")
    Next
    Set objXML = Nothing

    Response.Redirect "New.xml"
    %>

    clsXML.asp:

    <%
    Class clsXML
    'strFile must be full path to document, ie C:\XML\XMLFile.XML
    'objDoc is the XML Object
    Private strFile, objDoc

    '*********************************************************************
    ' Initialization/Termination
    '*********************************************************************

    'Initialize Class Members
    Private Sub Class_Initialize()
    strFile = ""
    End Sub

    'Terminate and unload all created objects
    Private Sub Class_Terminate()
    Set objDoc = Nothing
    End Sub

    '*********************************************************************
    ' Properties
    '*********************************************************************

    'Set XML File and objDoc
    Public Property Let File(str)
    Set objDoc = Server.CreateObject("Microsoft.XMLDOM")
    objDoc.async = False
    strFile = str
    objDoc.Load strFile
    End Property

    'Get XML File
    Public Property Get File()
    File = strFile
    End Property

    '*********************************************************************
    ' Functions
    '*********************************************************************

    'Create Blank XML File, set current obj File to newly created file
    Public Function createFile(strPath, strRoot)
    Dim objFSO, objTextFile
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile(strPath, True)
    objTextFile.WriteLine("<?xml version=""1.0""?>")
    objTextFile.WriteLine("<" & strRoot & "/>")
    objTextFile.Close
    Me.File = strPath
    Set objTextFile = Nothing
    Set objFSO = Nothing
    End Function

    'Get XML Field(s) based on XPath input from root node
    Public Function getField(strXPath)
    Dim objNodeList, arrResponse(), i
    Set objNodeList = objDoc.documentElement.selectNodes(strXPath)
    ReDim arrResponse(objNodeList.length)
    For i = 0 To objNodeList.length - 1
    arrResponse(i) = objNodeList.item(i).Text
    Next
    getField = arrResponse
    End Function

    'Update existing node(s) based on XPath specs
    Public Function updateField(strXPath, strData)
    Dim objField
    For Each objField In objDoc.documentElement.selectNodes(strXPath)
    objField.Text = strData
    Next
    objDoc.Save strFile
    Set objField = Nothing
    updateField = True
    End Function

    'Create node directly under root
    Public Function createRootChild(strNode)
    Dim objChild
    Set objChild = objDoc.createNode(1, strNode, "")
    objDoc.documentElement.appendChild(objChild)
    objDoc.Save strFile
    Set objChild = Nothing
    End Function

    'Create a child node under root node with attributes
    Public Function createRootNodeWAttr(strNode, attr, val)
    Dim objChild, objAttr
    Set objChild = objDoc.createNode(1, strNode, "")
    If IsArray(attr) And IsArray(val) Then
    If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then
    Exit Function
    Else
    Dim i
    For i = LBound(attr) To UBound(attr)
    Set objAttr = objDoc.createAttribute(attr(i))
    objChild.setAttribute attr(i), val(i)
    Next
    End If
    Else
    Set objAttr = objDoc.createAttribute(attr)
    objChild.setAttribute attr, val
    End If
    objDoc.documentElement.appendChild(objChild)
    objDoc.Save strFile
    Set objChild = Nothing
    End Function

    'Create a child node under the specified XPath Node
    Public Function createChildNode(strXPath, strNode)
    Dim objParent, objChild
    For Each objParent In objDoc.documentElement.selectNodes(strXPath)
    Set objChild = objDoc.createNode(1, strNode, "")
    objParent.appendChild(objChild)
    Next
    objDoc.Save strFile
    Set objParent = Nothing
    Set objChild = Nothing
    End Function

    'Create a child node(s) under the specified XPath Node with attributes
    Public Function createChildNodeWAttr(strXPath, strNode, attr, val)
    Dim objParent, objChild, objAttr
    For Each objParent In objDoc.documentElement.selectNodes(strXPath)
    Set objChild = objDoc.createNode(1, strNode, "")
    If IsArray(attr) And IsArray(val) Then
    If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then
    Exit Function
    Else
    Dim i
    For i = LBound(attr) To UBound(attr)
    Set objAttr = objDoc.createAttribute(attr(i))
    objChild.SetAttribute attr(i), val(i)
    Next
    End If
    Else
    Set objAttr = objDoc.createAttribute(attr)
    objChild.setAttribute attr, val
    End If
    objParent.appendChild(objChild)
    Next
    objDoc.Save strFile
    Set objParent = Nothing
    Set objChild = Nothing
    End Function

    'Delete the node specified by the XPath
    Public Function deleteNode(strXPath)
    Dim objOld
    For Each objOld In objDoc.documentElement.selectNodes(strXPath)
    objDoc.documentElement.removeChild objOld
    Next
    objDoc.Save strFile
    Set objOld = Nothing
    End Function
    End Class
    %>


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    本人只會一點點XML.
    和ASP.以及FLASH.其它都不太懂.

    大家多多指教.

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/2/18 10:31:00
     
     swj8606 帅哥哟,离线,有人找我吗?天秤座1986-10-10
      
      
      等级:大一新生
      文章:7
      积分:77
      门派:XHTML.ORG.CN
      注册:2006/5/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给swj8606发送一个短消息 把swj8606加入好友 查看swj8606的个人资料 搜索swj8606在『 XML源码及示例(仅原创和转载) 』的所有贴子 引用回复这个贴子 回复这个贴子 查看swj8606的博客2
    发贴心情 
    怎么那么冷清哈

    ----------------------------------------------
    帅~~~~~~~~~~~~~~~~~~~~~~~~

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/17 15:19:00
     
     GoogleAdSense天秤座1986-10-10
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML源码及示例(仅原创和转载) 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/14 10:11:24

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms