SOAP XML response trouble

Johannes_NielsenJohannes_Nielsen Member Posts: 206
edited 2013-04-03 in NAV Three Tier
Hi

I just wanted to share this solution.

This is a soap response from a webservice which I wanted to traverse in NAV using XML DOM 6.0
(note the soap schema used on the first two nodes and the second schema used on the ValidateXmlAgainstSchemaResponse node)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <ValidateXmlAgainstSchemaResponse xmlns="http://someschema.org/">
      <ValidateXmlAgainstSchemaResult>
        <Message>One error found</Message>
        <ErrorCount>1</ErrorCount>
        <ValidationErrors>
          <ValidationError>
            <ErrorMessage>Errortext</ErrorMessage>
          </ValidationError>
        </ValidationErrors>
      </ValidateXmlAgainstSchemaResult>
    </ValidateXmlAgainstSchemaResponse>
  </soap:Body>
</soap:Envelope>

Right, but this code which seemed to have worked before now retruned an error

EVALUATE(errorCount, l_xmlReplyDoc.selectSingleNode('/soap:Envelope/soap:Body/ValidateXmlAgainstSchemaResponse/' +
'ValidateXmlAgainstSchemaResult/ErrorCount').text);

The error was this non-specific thing:
This message is for C/AL programmers:

This Automation variable has not been instantiated.
You can instantiate it by either creating or assigning it.

The selectSingleNode method was failing because the first two nodes from the root was using the soap schema.


So, my solution turned out to be the method of setProperty on the DOM document.
l_xmlReplyDoc.setProperty('SelectionNamespaces',
  'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
  'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '+
  'xmlns:xxxx="http://someschema.org"');

"xxxx" was named by me.

Resulting in this code.
EVALUATE(errorCount, l_xmlReplyDoc.selectSingleNode(
  './soap:Envelope/soap:Body/xxxx:ValidateXmlAgainstSchemaResponse/xxxx:ValidateXmlAgainstSchemaResult/xxxx:ErrorCount').text);

Stripping the document of schema could be another soluton.
Best regards / Venlig hilsen
Johannes Sebastian
MB7-840,MB7-841
Sign In or Register to comment.