I've been asked to create a piece of code that connects to a webservice, sends some information and handles the response.
Sending and collecting the response goes fine, but when trying to handle the response, I'm stomped by a blank namespace declaration
The responsexml I get is:
<s:Envelope xmlns:s="
http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SendOrderResponse xmlns="
http://tempuri.org/">
<SendOrderResult xmlns:a="
http://schemas.datacontract.org/2004/07/Scalepoint.Web.EasyClaims.Webservices.DealerManagement" xmlns:i="
http://www.w3.org/2001/XMLSchema-instance">
<a:Description>...</a:Description>
<a:ResultCode>SCHEMA_VALIDATION_ERROR</a:ResultCode>
<a:ResultDetails i:nil="true"/>
</SendOrderResult>
</SendOrderResponse>
</s:Body>
</s:Envelope>
To handle this I have:
// Create NameSpacemanager
XmlNamespaceManager := XmlNamespaceManager.XmlNamespaceManager(XmlDocument.NameTable);
XmlNamespaceManager.AddNamespace('s','
http://schemas.xmlsoap.org/soap/envelope/');
XmlNamespaceManager.AddNamespace('','
http://tempuri.org/');
XmlNamespaceManager.AddNamespace('a','
http://schemas.datacontract.org/2004/07/Scalepoint.Web.EasyClaims.Webservices.DealerManagement');
XmlNamespaceManager.AddNamespace('i','
http://www.w3.org/2001/XMLSchema-instance');
and then I want to do a:
//Find ResponseCode
XmlCurrNode := XmlDocument.SelectSingleNode('s:Envelope/s:Body/SendOrderResponse/SendOrderResult/a:ResultCode', XmlNamespaceManager);
Doing a SelectSingleNode on just 's:Body' works, as does selecting 's:Envelope/s:Body'.
But as soon as I go to the SendOrderResponse my Node is uninitialized
I suspect I'm using/declaring the manager incorrectly, so any pointers would be welcome.
Answers
Sorry if i misunderstood something. If you want to remove namespace from the response then you can check out the below link.
https://rockwithnav.wordpress.com/2016/03/29/remove-namespace-web-service-response-dotnet-variable/
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
Your method looks like it would work; at least without any namespaces I should be able to grab the various nodes as needed. Unfortunately I cannot find the MSXML.DOMDocumentClass component on the clients machine, so I can't use that option.
Just to clarify my terminology:
so, for instance, if you defined
XmlNamespaceManager.AddNamespace('soap','http://schemas.xmlsoap.org/soap/envelope/');
you would later use
XmlCurrNode := XmlDocument.SelectSingleNode('soap:Envelope/soap:Body', XmlNamespaceManager);
and by doing so select the element s:Body in your XML document.
Unfurtunately it didn't seem to help
I have changed the tempuri to:
XmlNamespaceManager.AddNamespace('blank','http://tempuri.org/')
and am now asking for
XmlDocument.SelectSingleNode('s:Envelope/s:Body/blank:SendOrderResponse/blank:SendOrderResult/a:ResultCode', XmlNamespaceManager)
But still it won't find anything for me.
I was using a node to select from, which didn't work. But if I use the XmlDocument it works fine.
Thank you vaprog