Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning an empty XmlNode

Status
Not open for further replies.

NevG

Programmer
Oct 10, 2000
162
GB
Hi Gang

I have a method that returns an XmlNode. Unless certain criteria are met in which case there is no node to return.

How can I force a returned NULL or an empty XmlNode (how do I create one of these)

Any help as quickly as possible woud be very appreciated....

Cheers

Nev G
 
Just set the variable of type XmlNode to null prior to returning. This is a "ref" variable, right?
Code:
  public void MyMethod(ref XmlNode MyNode)
  {
    MyNode = null;
  }
And to call it:
Code:
  XmlNode node;

  MyClass.MyMethod(ref node);

  if (null == node)
  {
    // returned nothing
  } else {
    // Got a node, do something with it
  }
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
private XmlNode MyFindUser()
{
try
{
XmlDocument doc = new XmlDocument(); // Here doc could be null or not null
doc.Load("users.xml");// If doc is null then goes in catch{}
XmlNode user; // Here user is null
XmlNode root = doc.DocumentElement; // Here we are sure the doc is not null but root could be null or not
user=root.SelectSingleNode("domain::user[identity/lastname='Doppo']"); // If root is null then goes in catch{}
if (user != null)
{
// node found
}
else
{
// node not found
}

}
catch (Excweption ex)
{
string sMsg = "Error loading users.xml file : " + ex.GetType() + ex.Message;
throw new Excepetion (sMsg);
}
return user;
}
How to make a XmlNode null ? Just declare it and assign null to it.

XmlNode node = null;
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top