转载请注明来源:vbs类天生xml文件
有两文件:
objxml.asp:测试文件
clsxml.asp:vbs类文件
代码:
objXML.asp')NextSet objXML = NothingResponse.Redirect 'New.xml'%>clsXML.asp:')objTextFile.WriteLine('')objTextFile.CloseMe.File = strPathSet objTextFile = NothingSet objFSO = NothingEnd Function'Get XML Field(s) based on XPath input from root nodePublic Function getField(strXPath)Dim objNodeList, arrResponse(), iSet objNodeList = objDoc.documentElement.selectNodes(strXPath)ReDim arrResponse(objNodeList.length)For i = 0 To objNodeList.length - 1arrResponse(i) = objNodeList.item(i).TextNextgetField = arrResponseEnd Function'Update existing node(s) based on XPath specsPublic Function updateField(strXPath, strData)Dim objFieldFor Each objField In objDoc.documentElement.selectNodes(strXPath)objField.Text = strDataNextobjDoc.Save strFileSet objField = NothingupdateField = TrueEnd Function'Create node directly under rootPublic Function createRootChild(strNode)Dim objChildSet objChild = objDoc.createNode(1, strNode, '')objDoc.documentElement.appendChild(objChild)objDoc.Save strFileSet objChild = NothingEnd Function'Create a child node under root node with attributesPublic Function createRootNodeWAttr(strNode, attr, val)Dim objChild, objAttrSet objChild = objDoc.createNode(1, strNode, '')If IsArray(attr) And IsArray(val) ThenIf UBound(attr)-LBound(attr) UBound(val)-LBound(val) ThenExit FunctionElseDim iFor i = LBound(attr) To UBound(attr)Set objAttr = objDoc.createAttribute(attr(i))objChild.setAttribute attr(i), val(i)NextEnd IfElseSet objAttr = objDoc.createAttribute(attr)objChild.setAttribute attr, valEnd IfobjDoc.documentElement.appendChild(objChild)objDoc.Save strFileSet objChild = NothingEnd Function'Create a child node under the specified XPath NodePublic Function createChildNode(strXPath, strNode)Dim objParent, objChildFor Each objParent In objDoc.documentElement.selectNodes(strXPath)Set objChild = objDoc.createNode(1, strNode, '')objParent.appendChild(objChild)NextobjDoc.Save strFileSet objParent = NothingSet objChild = NothingEnd Function'Create a child node(s) under the specified XPath Node with attributesPublic Function createChildNodeWAttr(strXPath, strNode, attr, val)Dim objParent, objChild, objAttrFor Each objParent In objDoc.documentElement.selectNodes(strXPath)Set objChild = objDoc.createNode(1, strNode, '')If IsArray(attr) And IsArray(val) ThenIf UBound(attr)-LBound(attr) UBound(val)-LBound(val) ThenExit FunctionElseDim iFor i = LBound(attr) To UBound(attr)Set objAttr = objDoc.createAttribute(attr(i))objChild.SetAttribute attr(i), val(i)NextEnd IfElseSet objAttr = objDoc.createAttribute(attr)objChild.setAttribute attr, valEnd IfobjParent.appendChild(objChild)NextobjDoc.Save strFileSet objParent = NothingSet objChild = NothingEnd Function'Delete the node specified by the XPathPublic Function deleteNode(strXPath)Dim objOldFor Each objOld In objDoc.documentElement.selectNodes(strXPath)objDoc.documentElement.removeChild objOldNextobjDoc.Save strFileSet objOld = NothingEnd FunctionEnd Class%>
登录后复制
以上就是vbs类天生xml文件 的内容,更多相关内容请关注PHP中文网(www.php.cn)!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2420410.html