Showing posts with label XML File validation. Show all posts
Showing posts with label XML File validation. Show all posts

Friday, October 5, 2018

Read XML file as string using Vbscript

hi folks, To read XML file as entirely string we can use below logic. Hope it will useful.

set xmldoc=createobject("MICROSOFT. XMLDOM")
xmldoc. async=false
xmldoc. load(recentxmlfilepath)
for each ochdnd in xmldoc. documentelement. childnodes
     strxmldocline=ochdnd. nodename & ":" & ochdnd. text & vbcrlf
xmldocdata= xmldocdata & strxmldocline
next
msgbox xmldocdata

cheers
Trupti

Monday, October 30, 2017

XML File validations using UFT

'function to load xml file and use globle xml object
Public Function fnLoadReadXMLFile(strFile,strFilePath)
Set objXMLFile=createobject("Microsoft.XMLDOM")
objXMLFile.async=False
Set gobjXMLFile=fnLoadXMLFile(strFilePath,objXMLFile)
End Function
'function to load xml file
Public Function fnLoadXMLFile(strFilePath,ByRef objXMLFile)
objXMLFile.Load(strFilePath)
If objXMLFile.parseError.ErrorCode=0 Then
Call fnDoneResult("XML File Loaded", "XML File Loaded Successfully.")
else
Call fnFailResult("XML File does not Loaded","XML File does not Loaded Successfully.")
End If
Set fnLoadXMLFile=objXMLFile
End Function
'function to read xml node value
Public Function fnRetriveXMLNodeValue(strXMLNode,ByRef objXMLFile)
Set ColNodes=objXMLFile.selectNodes(strXMLNode)
If ColNodes.length >0 Then
For each objNode in ColNodes
strXMLTempOld=objNode.Text
strXMLTemp=strXMLTemp & "|" & strXMLTempOld

If Left(strXMLTemp,1)="|" Then
strXMLTemp=Right(strXMLTemp, Len(strXMLTemp)-1)
End If
' strXMLClientIDAttr=objNode.getAttribute("strAttributeName")
Next
fnRetriveXMLNodeValue=strXMLTemp
Call fnDoneResult("XML Node value found","XML Node value" & strXMLTemp& " found")
ElseIf ColNodes.length=0 Then
strXMLTemp=""
fnRetriveXMLNodeValue=strXMLTemp
else
Call fnFailResult("XML Node value not found","XML Node value" & strXMLTemp& " not found")
End If
End Function
'function to read xml node attribute value
Public Function fnRetriveXMLNodeAttributeValue(strXMLNode,strAttributeName,ByRef objXMLFile)
Set ColNodes=objXMLFile.selectNodes(strXMLNode)
If ColNodes.length >0 Then
For each objNode in ColNodes
strXMLTemp=objNode.Text
strXMLAttriVal=objNode.getAttribute(strAttributeName)
Next
fnRetriveXMLNodeAttributeValue=strXMLAttriVal
Call fnDoneResult("XML Node Attribute value found","XML Node Attribute value " & strXMLAttriVal & " found")
ElseIf ColNodes.length=0 Then
strXMLAttriVal=""
fnRetriveXMLNodeAttributeValue=strXMLAttriVal
else
Call fnFailResult("XML Node Attribute value not found","XML Node Attribute value " & strXMLAttriVal & " not found")
End If
End Function
'function to modify xml node attribute value 
 Public Function fnModifyXMLNodeAttributeValue(strXMLNode,strAttributeName,strModifyTagVal,ByRef objXMLFile,strFilePath)
Set ColNodes=objXMLFile.selectNodes(strXMLNode)
If ColNodes.length >0 Then
For each objNode in ColNodes
objNode.Attributes.getNamedItem(strAttributeName).Text = strModifyTagVal
strXMLAttriVal=objNode.getAttribute(strAttributeName)
If strXMLAttriVal=strModifyTagVal Then
Call fnDoneResult("XML Node Attribute modified","XML Node Attribute value is modifed with " & strModifyTagVal)
else
Call fnFailResult("XML Node Attribute not modified","XML Node Attribute value is not modified with " & strModifyTagVal)
End If
objXMLFile.Save(strFilePath)
Call fnDoneResult("XML File save","XML File save with attribute change")
Next
'fnModifyXMLNodeAttributeValue=strXMLAttriVal
Call fnDoneResult("XML Node Attribute modified","XML Node Attribute value is modifed with " & strModifyTagVal)
'ElseIf ColNodes.length=0 Then
' strXMLAttriVal=""
'fnModifyXMLNodeAttributeValue=strXMLAttriVal
else
Call fnFailResult("XML Node Attribute not modified","XML Node Attribute value is not modified with " & strModifyTagVal)
End If
End Function