Forum Discussion

bharat_sethi's avatar
bharat_sethi
Occasional Contributor
12 years ago

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.
  • 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
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    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.
  • bharat_sethi's avatar
    bharat_sethi
    Occasional Contributor
    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
  • bharat_sethi's avatar
    bharat_sethi
    Occasional Contributor
    Thanks Alex,



    It would have been useful if xml is another part of the response.



    In my case, I wanted to save the complete response into XML file. i.e. As if we use SoapUI for every request, we get XML response and same response come from TestComplete but as object which we can explore. To save the complete response of the method as XML following code is useful and worked for me.

    SET RESPONSE = webservices.VaultRetrievalModified.GetListOfDocuments(datasetinput.Value(0),datasetinput.Value(1),datasetinput.Value(2))

    WebServices.VaultRetrievalModified.LastResponse.Save("C:\Saturn-Testing\Responce.xml")

    XML.GetListOfDocuments.Check WebServices.VaultRetrievalModified

    ' Require MSXML6.0 can be downloded from http://www.microsoft.com/en-us/download/details.aspx?id=6276

    ' Require another extension of test complete available at http://support.smartbear.com/viewarticle/42198/

    Result = objectXML.validateXMLbyXSD("C:\Saturn-Testing\Responce.xml","C:\Saturn-Testing\williamslea.com.DocumentArchive.DocumentRetrieval.xsd")