XmlNode error

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello,I am doing this:
XmlNode name=this.oXmlDoc.SelectSingleNode(e.Node.Text);
MessageBox.Show(name.LocalName.ToString());

But get the following error:

Object reference not set to an instance of an object.

Why?
Thank you!
 
juli said:
Hello,I am doing this:
XmlNode name=this.oXmlDoc.SelectSingleNode(e.Node.Text);
MessageBox.Show(name.LocalName.ToString());

But get the following error:

Object reference not set to an instance of an object.

SelectSingleNode can return null when it does not find a matching node
so you would need to check
XmlNode name = this.oXmlDoc.SelectSingleNode(e.Node.Text);
if (name != null) {
MessageBox.Show(name.LocalName.ToString());
}
 
Back
Top