vbs class generates xml file
Please indicate the source when reprinting: vbs class generated xml file
There are two files:
objXML.asp: test file
clsXML.asp: vbs class file
Code:
objXML.asp <%@ Language=VBScript %><% Option Explicit %><!--#INCLUDE FILE='clsXML.asp'--><%Dim objXML, strPath, strSet 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 NodeobjXML.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 updatedobjXML.updateField 'Jobs[@Size=24]', '24's' 'Notice that only two nodes have the specified XPath, hence 'only two new child nodes will be addedobjXML.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>')NextSet 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 ObjectPrivate strFile, objDoc '*********************************************************************' Initialization/Termination'********************************************************************* 'Initialize Class MembersPrivate Sub Class_Initialize()strFile = ''End Sub 'Terminate and unload all created objectsPrivate Sub Class_Terminate()Set objDoc = NothingEnd Sub '*********************************************************************' Properties'********************************************************************* 'Set XML File and objDocPublic Property Let File(str)Set objDoc = Server.CreateObject('Microsoft.XMLDOM')objDoc.async = FalsestrFile = strobjDoc.Load strFileEnd Property 'Get XML FilePublic Property Get File()File = strFileEnd Property '*********************************************************************' Functions'********************************************************************* 'Create Blank XML File, set current obj File to newly created filePublic Function createFile(strPath, strRoot)Dim objFSO, objTextFileSet objFSO = Server. CreateObject('Scripting.FileSystemObject')Set objTextFile = objFSO.CreateTextFile(strPath, True)objTextFile.WriteLine('<?xml version=''1.0''?>')objTextFile. WriteLine('<' & strRoot & '/>')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%>
The above is the content of the vbs class generated xml file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The speed of mobile XML to PDF depends on the following factors: the complexity of XML structure. Mobile hardware configuration conversion method (library, algorithm) code quality optimization methods (select efficient libraries, optimize algorithms, cache data, and utilize multi-threading). Overall, there is no absolute answer and it needs to be optimized according to the specific situation.

It is impossible to complete XML to PDF conversion directly on your phone with a single application. It is necessary to use cloud services, which can be achieved through two steps: 1. Convert XML to PDF in the cloud, 2. Access or download the converted PDF file on the mobile phone.

It is not easy to convert XML to PDF directly on your phone, but it can be achieved with the help of cloud services. It is recommended to use a lightweight mobile app to upload XML files and receive generated PDFs, and convert them with cloud APIs. Cloud APIs use serverless computing services, and choosing the right platform is crucial. Complexity, error handling, security, and optimization strategies need to be considered when handling XML parsing and PDF generation. The entire process requires the front-end app and the back-end API to work together, and it requires some understanding of a variety of technologies.

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

XML formatting tools can type code according to rules to improve readability and understanding. When selecting a tool, pay attention to customization capabilities, handling of special circumstances, performance and ease of use. Commonly used tool types include online tools, IDE plug-ins, and command-line tools.

An application that converts XML directly to PDF cannot be found because they are two fundamentally different formats. XML is used to store data, while PDF is used to display documents. To complete the transformation, you can use programming languages and libraries such as Python and ReportLab to parse XML data and generate PDF documents.

Use most text editors to open XML files; if you need a more intuitive tree display, you can use an XML editor, such as Oxygen XML Editor or XMLSpy; if you process XML data in a program, you need to use a programming language (such as Python) and XML libraries (such as xml.etree.ElementTree) to parse.

XML Online Format Tools automatically organizes messy XML code into easy-to-read and maintain formats. By parsing the syntax tree of XML and applying formatting rules, these tools optimize the structure of the code, enhancing its maintainability and teamwork efficiency.
