add xml as a child node in exsiting xml using vb6 - vb6

I have existing xml and trying to add an new xml as a child node.but it converting child xml in weird format.Child xml's all the tag < converted as &lt and all /> converted in &gt
I am using this vb code
objAdjoin.appendChild .createElement("DOCCHKLIST")
objAdjoin.selectSingleNode("DOCCHKLIST").appendChild .createTextNode(DocCheckListXML)
Child XML :
<DOCCHKLIST><DOCCHK><CDSEQGER>800</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK><DOCCHK><CDSEQGER>801</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK></DOCCHKLIST>
Output :
<Message><Output><AANO>MMG050069</AANO><LOADSCLSEQ>MMG050069</LOADSCLSEQ><RLOSCOLLSEQNO>SKE050003</RLOSCOLLSEQNO><CLCHKLSTTYPE>ASNB/UTRS</CLCHKLSTTYPE><DOCCHKLIST><DOCCHK><CDSEQGER>800</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK><DOCCHK><CDSEQGER>801</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK></DOCCHKLIST><Status>00</Status><ErrorMessage>Processing Complete</ErrorMessage></Output></Message>

Without adding the child nodes individually I have managed to get it to work as follows:
Private Sub Command_Click()
Dim objDomDoc As DOMDocument60
Dim objDom1 As DOMDocument60
Dim strParent As String
Dim strChild As String
Dim objAdJoin As IXMLDOMElement
strParent = "<Message><Output><AANO>MMG050069</AANO><LOADSCLSEQ>MMG050069</LOADSCLSEQ><RLOSCOLLSEQNO>SKE050003</RLOSCOLLSEQNO><CLCHKLSTTYPE>ASNB/UTRS</CLCHKLSTTYPE></Output></Message>"
strChild = "<DOCCHKLIST><DOCCHK><CDSEQGER>800</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK><DOCCHK><CDSEQGER>801</CDSEQGER><RLOSDOCSEQNO>MCV3453</RLOSDOCSEQNO><CLSEQNO>1</CLSEQNO></DOCCHK></DOCCHKLIST>"
Set objDomDoc = New DOMDocument60
Set objDom1 = New DOMDocument60
objDomDoc.loadXML (strParent)
objDom1.loadXML strChild
Set objAdJoin = objDomDoc.firstChild
objAdJoin.appendChild objDomDoc.createElement("DOCCHKLIST")
objAdJoin.selectSingleNode("DOCCHKLIST").appendChild objDom1.firstChild
Debug.Print objAdJoin.xml
End Sub
You will need to check the parseError property to see if there have been any issues with the load. You will also end up with two nodes called DOCCHKLIST.

Related

Using HP-UFT, is Is there anyway to tell whether or not an object in the object repository is being used in other tests?

I'm currently using UFT -- I have a GUI test, and there's a web element object in one of my tests I'd like to delete/update, but I'm worried it's being referenced by another test in our test suite. (I am coming into a test suite that someone else built)
Is there anyway to tell whether or not an object in the object repository is being used in other tests? (Without having to go into each individual test and action to find out?)
My way would be simple recursive file search.
Open EditPlus
Search -> Find In Files
Find What =
File Type = *.mts | *.vbs | *.qfl
Folder =
Select the Include Sub Folder Check Box
Click Find
You can use Search>View>Find (or ctrl+F) from UFT and select to look in entire solution
Open "Script.mts" file from every action and search for your object name. If you find the object, write the script name and line number where your object exists, in a file.
Use the below code:
'strScriptsPath is the path where your test script folders are placed.
Set strScripts = objFSO.GetFolder(strScriptsPath).SubFolders
For Each Script In strScripts
strAction = strScriptsPath & "\" & Script.Name & "\Action1\Script.mts"
If objFSO.FileExists(strAction) Then
'Open Script in NotePad
Set strFile = objFSO.OpenTextFile(strAction, 1)
Do While Not (strFile.AtEndOfStream)
strLine = strFile.ReadLine
If InStr(1, strLine, strObjectName) > 0 Then
iVerificationCount = objSheet.UsedRange.Rows.Count
iCurrentRow = iVerificationCount + 1
objSheet.Cells(iCurrentRow, 1) = Script.Name
objSheet.Cells(iCurrentRow, 2) = strLine
If strFile.AtEndOfStream Then
objSheet.Cells(iCurrentRow, 3) = strFile.Line
Else
objSheet.Cells(iCurrentRow, 3) = strFile.Line - 1
End If
End If
Loop
strFile.Close
Set strFile = Nothing
End If
Next
Set strScripts = Nothing
To be able to use this code, declare objFSO object and write a piece of code to create an excel and get objSheet.
You can also replace the object name using the below code:
Use the For Each Loop as mentioned above
strScript = strScriptsPath & "\" & strScriptName & "\Action1\Script.mts"
strFind = "Old Object Name"
strReplace = "New Object Name"
Set strFile = objFSO.OpenTextFile(strScript, 1)
strData = strFile.ReadAll
strNewData = Replace(strData, strFind, strReplace)
strFile.Close
Set strFile = Nothing
Set strFile = objFSO.OpenTextFile(strScript, 2)
strFile.Write strNewData
strFile.Close
Set strFile = Nothing
** You just need to write this entire code in a .vbs file and run that file.

ASP Classic "Microsoft VBScript runtime error '800a01a8' Object required: 'hashHelp'"

Here I have a double Directory that is suppose to be carrying information from a database in the form of the object hashHelp. Clearly, this isn't working.
Based on everything I've found on this website and around the web, this error message seems to imply that the object hashHelp isn't being created, but you can clearly see it being created above. I have check Any idea what could be happening?
do until rs.eof
if valid(cart, rs, data) = true then
Dim hashHelp
Set hashHelp = new HashHelper
hashHelp.setCode(rs.Fields("Code"))
hashHelp.setDateTime(rs.Fields("ScanTime"))
Dim entry
entry = DateDiff("d", beginDate, DateValue(rs.Fields("ScanTime")))
hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) = arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) + 1
End If
rs.movenext
loop
rs.close
The line the error happens on is hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
I've checked all the other variable and they are being created and used just fine.

Google Spreadsheet to SSIS VB Code issue

Requirement:
Convert Google Spreadsheet data to SQL Server through SSIS.
Method:
With help from this website, I'm doing coding in Visual Studio 2015 Community edition. I have prepared Variables, Control Flow, Data Flow and added Script component and the required Google References.
Code pasted in VS as Visual Basic 2015:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports Google.GData.Client
Imports Google.GData.Extensions
Imports Google.GData.Spreadsheets
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> 'Line 15 Error here
<CLSCompliant(False)> 'Line 17 Error here
Public Class ScriptMain
Inherits UserComponent
Dim objListFeed As ListFeed
Public Overrides Sub PreExecute()
MyBase.PreExecute()
Dim objService As SpreadsheetsService
Dim objWorkSheetQuery As WorksheetQuery
Dim objWorkSheetFeed As WorksheetFeed
Dim objWorkSheet As WorksheetEntry
Dim objListFeedLink As AtomLink
Dim objListQuery As ListQuery
Dim bt(0) As Byte
'Create a connection to the google account
objService = New SpreadsheetsService("exampleCo-exampleApp-1")
Me.Log(Variables.strPassword, 0, bt)
Me.Log(Variables.strUserName, 0, bt)
objService.setUserCredentials(Variables.strUserName, Variables.strPassword)
Me.Log("Service: " + Variables.strUserName, 0, bt)
'Connect to a specific spreadsheet
objWorkSheetQuery = New WorksheetQuery(Variables.strKey, "private", "full")
objWorkSheetFeed = objService.Query(objWorkSheetQuery)
objWorkSheet = objWorkSheetFeed.Entries(0)
Me.Log("Spreadsheet: " + objWorkSheet.Title.Text.ToString, 0, bt)
'Get a list feed of all the rows in the spreadsheet
objListFeedLink = objWorkSheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, Nothing)
objListQuery = New ListQuery(objListFeedLink.HRef.ToString())
objListFeed = objService.Query(objListQuery)
Me.Log("ListFeed: " + objListFeed.Feed.ToString, 0, bt)
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
End Sub
Public Overrides Sub CreateNewOutputRows()
Dim objRow As ListEntry
For Each objRow In objListFeed.Entries
With Output0Buffer
.AddRow()
.Product = objRow.Elements.Item(0).Value
.Qty = objRow.Elements.Item(1).Value
End With
Next
Output0Buffer.EndOfRowset()
End Sub
End Class
Problem:
Upon pressing Build, I get the following error on Line 15 and 17.
BC32035 VB.NET Attribute specifier is not a complete statement. Use a
line continuation to apply the attribute to the following statement.
Here it says to add a space and underscore following the attribute, however, when I add them they are just automatically removed.
I just created a new script component in a new SSIS package dataflow, and here are the lines between the import block and the Class declaration:
' This is the class to which to add your code. Do not change the name, attributes, or parent
' of this class.
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
I have never heard of the situation you describe where the underscores just "disappear", but maybe if you paste these lines over your lines it will work.
If not, you may need to copy your code to the clipboard, and then destroy the script component and create a new one, and paste your code into it.

Update data from RSS with vbscript

I'm writing a VBScript file (*.vbs) that should get data from this RSS and export them to text file. I searched the internet but found nothing about this.
Does anyone know any sources to use for creating such function ?
P.S. The RSS just shows the currency rates for a date. Thanks.
To get you started, in vbscript you can
Load the data into a DomDocument, as RSS is XML
Option Explicit
dim xmldoc: set xmldoc = CreateObject("MSXML2.DomDocument.6.0")
xmldoc.async = false
xmldoc.setProperty "SelectionLanguage", "XPath"
xmldoc.load "https://www.cba.am/_layouts/rssreader.aspx?rss=280F57B8-763C-4EE4-90E0-8136C13E47DA"
Run a query to get what you want using XPath
' obviously, you need to change this to your requirements
' here, we're just getting every item node
dim items: set items = xmldoc.selectNodes("//item")
Output the text to file
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
dim stream: set stream = fso.OpenTextFile("data.txt", 2, true)
dim item
for each item in items
' again, this changes to your requirements
' this just writes the text content of all the items and child
' nodes
stream.WriteLine item.text
next 'item
stream.Close

How to get Business component instance number from QC/ALM

I am working on BPT framework on QTP and for a testcase i am using same component multiple times. I want to fetch the Business component instance number from QC ->Testplan->TestCase->Business component. Based on the instance number i will read the required component parameters from excel sheet.
Thanks.
Below code worked for me:
Set TestTree = TestSet.TSTestFactory
Set TestList = TestTree.NewList("")
For Each TSTest In TestList
Set Test = TSTest.Test
Set objTestFactory = tdc.TestFactory
Set tFilter = objTestFactory.Filter
tFilter.Filter("TS_TEST_ID") = Test.ID
Set tList = objTestFactory.NewList(tFilter.Text)
Dim objTest
For Each tst In tList
If tst.Type = "BUSINESS-PROCESS" Then
Set objTest = tst
Exit For
End If
Next
If objTest Is Nothing Then
Else
Dim BPTest As BusinessProcess
Set BPTest = objTest
BPTest.Load
' Get list if component instance from the Test
Set components = BPTest.BPComponents
Set Component = components.Item(1)
For i = 1 To BPTest.BPComponents.Count
componentName = components.Item(i).Name
componentInstanceId = components.Item(i).ID
ComponentId = components.Item(i).Component.ID
Next
End if
Next
This code will fetch the details from the test lab level and go until the business component level. Currently it is extracting the component name and id. You can modify the code as per your need.
Visit tutorial at knowlzz . It has explained the solution nicely with each and every detail.

Resources