SOAP XML response trouble

Johannes_Nielsen
Member Posts: 206
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)
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:
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.
"xxxx" was named by me.
Resulting in this code.
Stripping the document of schema could be another soluton.
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
Johannes Sebastian
MB7-840,MB7-841
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions