SelectSingleNode return Nothing instead of Null

SelectSingleNode return Nothing instead of Null

am 15.01.2008 15:29:28 von 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.

Re: SelectSingleNode return Nothing instead of Null

am 15.01.2008 15:41:22 von Leon Mayne

"Larry Bud" wrote in message
news:087872cf-b0be-4579-815d-89a436f5941e@d4g2000prg.googleg roups.com...
> 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
}