In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Although most of the data are stored in the database today, irresistible factors such as power outages and power outages often interrupt the automation. At this time, it is much more convenient for these non-business configuration data to be stored with xml. The following is the implementation method of reading XML files with VBScript scripts, recorded as a memo.
1. Node information of XML file:
1 TNSLogon ELOG ASD asd 1 3 TNSLogon NAV12C2 navdev navdev 0 5 DirectLogon RTTD devman devman 0
two。 Determine the version of the MSXML.dll component of the current system (since there are usually multiple versions in the system, only the largest version is taken here)
Function iGetMSxmlVersion () Dim SystemPath, fso, f, fa, fname, iVersion, iMaxVersion SystemPath = "C:\ Windows\ System32" 'system path Set fso = CreateObject ("Scripting.FileSystemObject") If fso.FolderExists (SystemPath) Then Set f = fso.GetFolder (SystemPath) Set fa = f.Files iMaxVersion = 0' calc the amount of files For Each fname in fa If Instr (fname "msxml") > 0 Then iVersion = Mid (fname.name,6,1) If IsNumeric (iVersion) Then If iMaxVersion
< iVersion Then iMaxVersion = iVersion End If End If End If Next If iMaxVersion >0 Then iGetMSxmlVersion = iMaxVersion Log.Message ("The max MSxml version is:" + iMaxVersion) Else iGetMSxmlVersion = 0 Log.Error ("The current system not exist MSxml module.") End IfEnd IfEnd Function
3. Read the xml file function:
Function sGetDataFromXML (sXmlPath, sRoot, sNode, iDataID SColumn) Dim xmlVersion xmlVersion = iGetMSxmlVersion If sXmlPath "" and sRoot "" and sNode "" and iDataID "" and sColumn "" Then If xmlVersion 0 Then 'Create COM object Set Doc = Sys.OleObject ("Msxml2.DOMDocument." + xmlVersion + ".0")' you can also use the following method to create XMLDOM object 'Set Doc = CreateObject ("Microsoft.XMLDOM") Doc.async = False 'Load data from a file' We use the file created earlier Call Doc.load (sXmlPath) 'Report an error If, for instance The markup or file structure is invalid If Doc.parseError.errorCode 0 Then s = "Reason:" + Chr (9) + Doc.parseError.reason + _ "Line:" + Chr (9) + CStr (Doc.parseError.line) + Chr (13) + Chr (10) + _ "Pos:" + Chr (9) + CStr (Doc.parseError.linePos) + Chr (13) + Chr (10) + _ "Source:" + Chr (9) + Doc.parseError.srcText 'Post an error to the log and exit Call Log.Error ("Cannot parse the document." S) Exit Function End If 'Use an XPath expression to obtain a list of "control" nodes Set Nodes = Doc.selectNodes ("/" + sRoot + "/" + sNode + "[DataID=" + CStr (iDataID) + "] /" + sColumn) If Not (Nodes.item (0) is Nothing) Then Call Log.Message ("Data from XML:" + Nodes.item (0) .text) sGetTestDataFromXML = Nodes.item (0) .text Else Log.Error ("Read XML nodes occur errors.") Exit Function End If Set Nodes = Nothing Set Doc = Nothing Else Exit Function End If Else Log.Error ("Function sGetTestDataFromXML () occur incorrect parameters.") Exit Function End IfEnd Function
4. Test script and log output in TestComplete:
Sub Test Dim strXmlPath, strTNSName, strUserame, strPassword strXmlPath=Project.Path + "Data\ TC_TNSInfo.xml" log.Message (strXmlPath) If aqFile.Exists (strXmlPath) Then strTNSName = sGetTestDataFromXML (strXmlPath, "TC_TestLogon", "TNSLogon", 3, "I_TNSName") strUserame = sGetTestDataFromXML (strXmlPath, "TC_TestLogon", "TNSLogon", 3, "I_Username") strPassword = sGetTestDataFromXML (strXmlPath, "TC_TestLogon", "TNSLogon", 3 "I_Password") log.Message ("TNSName is:" + strTNSName) log.Message ("Username is:" + strUserame) log.Message ("Password is:" + strPassword) End IfEnd Sub
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.