all groups > dotnet xml > june 2007 >
You're in the

dotnet xml

group:

XML getting the namespace


XML getting the namespace maflatoun NO[at]SPAM gmail.com
6/28/2007 1:14:44 AM
dotnet xml:
Hi,

I'm working on a ASP.NET component with one requirement being to catch
Web Service exceptions. I've managed to get it working using the
following code

XmlDocument doc = new XmlDocument();
doc.LoadXml(se.Detail.OuterXml);
XmlNamespaceManager nsManager = new
XmlNamespaceManager(doc.NameTable);

nsManager.AddNamespace("prefix", "http://localhost/site/test/
webservice.asmx");

string errorMessage = doc.DocumentElement.SelectSingleNode("//
prefix:ErrorMessage", nsManager).InnerText;
Response.Write("Error message:" + errorMessage);

The issue is that the namespace changes depending on where the web
service resides (ex. staging, production, local computer). How can I
get the http://localhost/site/test/webservice.asmx dynamically (parse
it from XmlDocument?)

Thanks
Maz
Re: XML getting the namespace maflatoun NO[at]SPAM gmail.com
6/28/2007 6:19:53 AM
[quoted text, click to view]

Thank you for your reply. Can you please show me or point me to an
article for configuring web services in a way that the namespace does
not change?

Thanks
Maz.
Re: XML getting the namespace maflatoun NO[at]SPAM gmail.com
6/28/2007 6:23:02 AM
[quoted text, click to view]

Never mind. Dumb question. I got it.

Thx
Maz
Re: XML getting the namespace Martin Honnen
6/28/2007 1:47:36 PM
[quoted text, click to view]

I would suggest to configure your web service in a way that the
namespace does not change. That is possible as a namespace does not have
to refer to an existing resource.

If you want to read out namespaces from an XmlDocument then how you do
that depends on the structure of the XML. If there is just one default
namespace declaration on the root element e.g.
<root xmlns="http://example.com/2007/ns1">
then you can simply access
doc.DocumentElement.namespaceURI
(where doc is your XmlDocument instance).

Using SelectSingleNode or SelectNodes you are also able to access the
namespace nodes the XPath data model knows. If you need help with that
then show us a relevant sample of the XML.

--

Martin Honnen --- MVP XML
Re: XML getting the namespace Martin Honnen
6/28/2007 3:27:47 PM
[quoted text, click to view]

The namespace URI is simply a name so you can set up your namespaces
with an attribute as follows:

[WebService(Description="My Service", Namespace="http://example.com/ws1/")]

Choose a name that you own/control like a domain name you control.


--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button