bharat_sethi
12 years agoOccasional Contributor
Save output of a WebServise method (XML) in to XML file
We are require to perform validation of Web service output against XSD.
As for each web service call a XML response generated which gets stored in an object
e.g.
SET RESPONSE = webservices.VaultRetrievalModified.GetListOfDocuments(datasetinput.Value(0),datasetinput.Value(1),datasetinput.Value(2))
Now i need to validate the response against XSD but as response is an object,
1. Either i have to save it as XML or
2. Manage to convert stores check point with new values and then need to validate against xsd.
to use:
objectXML.validateXMLbyXSD(xmlpath,xsdfilepath)
Please advise how to save output of Web service method into XML file or any other way to validated XML against XSD.
As for each web service call a XML response generated which gets stored in an object
e.g.
SET RESPONSE = webservices.VaultRetrievalModified.GetListOfDocuments(datasetinput.Value(0),datasetinput.Value(1),datasetinput.Value(2))
Now i need to validate the response against XSD but as response is an object,
1. Either i have to save it as XML or
2. Manage to convert stores check point with new values and then need to validate against xsd.
to use:
objectXML.validateXMLbyXSD(xmlpath,xsdfilepath)
Please advise how to save output of Web service method into XML file or any other way to validated XML against XSD.
- Hi Bharat,
Stop the test on the breakpoint after the Set Response = ... line and investigate the Response variable in the debugger. Usually, you should get access to the returned xml as Response.xml or Response.xml.OleValue or something like that. - Following code can be used when XML to be validated against multiple XSD, be sure about the sequence.
This first one should be the one which does not import anything and then the following XSD to be added.
Sub ValidateXML(XMLPath)
dim XSDScheema(4)
XSDScheema(0) = "P:\XYZ\schemas.microsoft.com.2003.10.Serialization.xsd"
XSDScheema(1) = "P:\XYZ\schemas.microsoft.com.2003.10.Serialization.Arrays.xsd"
XSDScheema(2) = "P:\XYZ\DocumentArchive.DocumentRetrieval.contracts.xsd"
XSDScheema(3) = "P:\XYZ\DocumentArchive.DocumentRetrieval.xsd"
dim Namespace(4)
Namespace(0) = "http://schemas.microsoft.com/2003/10/Serialization/"
Namespace(1) = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"
Namespace(2) = "http://XYZ.com/DocumentArchive/DocumentRetrieval/contracts"
Namespace(3) = "http://XYZ.com/DocumentArchive/DocumentRetrieval"
' Create COM object
' If you have MSXML 4:
Set Doc = Sys.OleObject("Msxml2.DOMDocument.6.0")
Set LoadDoc = Sys.OleObject("Msxml2.DOMDocument.6.0")
Set cas = sys.OleObject("Msxml2.XMLSchemaCache.6.0")
'Set ObjErr = sys.OleObject("Msxml2.IXMLDOMParseError")
LoadDoc.async = false
LoadDoc.validateOnParse = false
LoadDoc.resolveExternals = false
LoadDoc.load XSDScheema(0) cas.add Namespace(0),LoadDoc
LoadDoc.load XSDScheema(1) 'XSDPath '"C:\Saturn-Testing\williamslea.com.DocumentArchive.DocumentRetrieval.xsd"
cas.add Namespace(1),LoadDoc
LoadDoc.load XSDScheema(2) 'XSDPath '"C:\Saturn-Testing\williamslea.com.DocumentArchive.DocumentRetrieval.xsd"
cas.add Namespace(2),LoadDoc
LoadDoc.load XSDScheema(3) 'XSDPath '"C:\Saturn-Testing\williamslea.com.DocumentArchive.DocumentRetrieval.xsd"
cas.add Namespace(3),LoadDoc
Doc.async = false
Doc.validateOnParse = false
Doc.resolveExternals = false
Doc.schemas = cas
Doc.loadXML (XMLPath) '"C:\Saturn-Testing\Responce.xml")
if Doc.parseError.errorCode <> 0 then
log.Error("XML Validation error:" + Doc.parseError.reason)
Else
log.Message(Doc.xml)
End if