How do I declare a blank namespace with the .NET components?

Sunset
Member Posts: 201
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.
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.
Don't just take my word for it, test it yourself
0
Best Answer
-
Just give the blank namespace a proper prefix when you create the namespace manager and use this prefix in SelectSingleNode. The prefix you use does not need to match the one that is used in the document, the namespace name (http://tempuri.org/ in your case) must match.
Just to clarify my terminology:xmlns:prefix="namespace name"
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.5
Answers
-
Hey Sunset,
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/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
I don't really want the namespaces removed, just to be able to select the node.
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.Don't just take my word for it, test it yourself0 -
Just give the blank namespace a proper prefix when you create the namespace manager and use this prefix in SelectSingleNode. The prefix you use does not need to match the one that is used in the document, the namespace name (http://tempuri.org/ in your case) must match.
Just to clarify my terminology:xmlns:prefix="namespace name"
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.5 -
That cleared up something about namespaces for me; thank you
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.Don't just take my word for it, test it yourself0 -
What I wrote turned out to be not exactly correct
I was using a node to select from, which didn't work. But if I use the XmlDocument it works fine.
Thank you vaprogDon't just take my word for it, test it yourself0
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