XML Scripts
VBScript to read XML
Set xmlDoc = CreateObject(“Msxml2.DOMDocument”)
xmlDoc.load(“D:\gcreddy.xml”)
xmlDoc.load(“D:\gcreddy.xml”)
Set ElemList = xmlDoc.getElementsByTagName(“segment”)
filepath = ElemList.item(0).getAttribute(“filePath”)
MsgBox filepath
filepath = ElemList.item(0).getAttribute(“filePath”)
MsgBox filepath
Set ElemList = xmlDoc.getElementsByTagName(“description”)
plot = ElemList.item(0).Text
MsgBox plot
plot = ElemList.item(0).Text
MsgBox plot
How Get Root Element attribute’s value from XML file
Function GetRootElementAttributeValueFromXML(sFileNameWithPath,sAttribute)
‘ Why we need to ADD 2 because each attribute followed by (=) and (“)
iLenOfValue=len(sAttribute) + 2
Set doc = XMLUtil.CreateXML()
doc.LoadFile sFileNameWithPath
Set root = doc.GetRootElement()
IF instr(1,root,sAttribute) <= 0 then
Reporter.ReportEvent micFail,sAttribute,”Not Found in XML file.”
exitrun(0)
Else
sStartPos=instr(1,root,sAttribute) + iLenOfValue
sEndPos=instr(sStartPos,root,”"”")
GetRootElementAttributeValueFromXML=mid(root,sStartPos,sEndPos – sStartPos)
End if
End Function
msgbox(GetRootElementAttributeValueFromXML(“c:\temp\gcreddy.xml”,”MerchantId”))
‘ Why we need to ADD 2 because each attribute followed by (=) and (“)
iLenOfValue=len(sAttribute) + 2
Set doc = XMLUtil.CreateXML()
doc.LoadFile sFileNameWithPath
Set root = doc.GetRootElement()
IF instr(1,root,sAttribute) <= 0 then
Reporter.ReportEvent micFail,sAttribute,”Not Found in XML file.”
exitrun(0)
Else
sStartPos=instr(1,root,sAttribute) + iLenOfValue
sEndPos=instr(sStartPos,root,”"”")
GetRootElementAttributeValueFromXML=mid(root,sStartPos,sEndPos – sStartPos)
End if
End Function
msgbox(GetRootElementAttributeValueFromXML(“c:\temp\gcreddy.xml”,”MerchantId”))
0 comments:
Post a Comment