Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Verifying if namespace exists
Message
From
25/07/2015 04:12:09
 
 
To
24/07/2015 16:22:29
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01622469
Message ID:
01622501
Views:
38
>>https://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.hasnamespace(v=vs.110).aspx ?
>
>I thought about that but it seems that one is what we have loaded in the XML namespace manager and not as per the XML.
>
>Thinking of it, I do not think it is possible. The only way to resolve this is to trap it in the code. For example, once the namespace loaded, I will look up for a specific node. If that does not work, it would then be either the node does not exist or the namespace was not properly defined.

Ha. Misread your requirements - thought you just wanted to check whether it was already defined. If you want to populate the NameTable with all of the namespaces used in a specific piece of XML I came across this approach:
 XmlDocument doc = new XmlDocument();
 doc.LoadXml(*whatever*);
XmlNodeList nameSpaceList = doc.SelectNodes(@"//namespace::*[not(. = ../../namespace::*)]");
 var _xmlNSmgr = new XmlNamespaceManager(doc.NameTable);
foreach (XmlNode nsNode in nameSpaceList)
            {
                _xmlNSmgr.AddNamespace(nsNode.LocalName, nsNode.Value);
            }
Only made a quick test but it seems to work......
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform