devxlogo

Retrieve Specific Nodes When They Contain an xmlns Namespace Parameter

Retrieve Specific Nodes When They Contain an xmlns Namespace Parameter

When an XML file contains a xmlns parameter, you can’t use simple SelectSingleNode to retrieve a specific node. Take the following code, for example:

       31  

Now, try to run the following code with the above XML:

Running the above code will generate the following error message:

System.NullReferenceException: Object reference not set to an instance of an object.Line 16:  Response.Write ("Node Name : " + node.Name); 

The solution is to specifiy the namespace for the XPath. The following code solves the problem and retrieves the node:

devx-admin

Share the Post: