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....
  • AlexKaras's avatar
    12 years ago
    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
    12 years ago
    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