SelectSingleNode return Nothing instead of Null

L

Larry Bud

Probably just a mistake in the documentation:

Public Overridable Function SelectSingleNode(ByVal xpath As String) As
System.Xml.XPath.XPathNavigator
Member of: System.Xml.XPath.XPathNavigator
Summary:

Selects a single node in the System.Xml.XPath.XPathNavigator using the
specified XPath query.

Parameters:
xpath: A System.String representing an XPath expression.

Return Values:
An System.Xml.XPath.XPathNavigator object that contains the first
matching node for the XPath query specified; otherwise, null if there
are no query results.
------------------------
The problem is that if it doesn't find the Xpath, it returns NOTHING,
not NULL.

I need to retrieve about 15 individual values. They are all
optional. So without putting a try/catch block around every request,
I have a function that checks if the value is nothing, and if so,
return an empty string, otherwise return the value.

Any better way to do this? This is part of a time critical app so
efficiency is of utmost importance.
 
L

Leon Mayne

Larry Bud said:
The problem is that if it doesn't find the Xpath, it returns NOTHING,
not NULL.

Nothing is NULL for vb.net. There shouldn't be a difference in how you test
between the languages:

Dim xnMyNode as XmlNode = xdDocument.SelectSingleNode("myXpath")
If xnMyNode IsNot Nothing then
' Do stuff
End If

XmlNode xnMyNode = xdDocument.SelectSingleNode("myXpath");
if (xnMyNode != null)
{
// Do stuff
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top