how to check whether some entered InnerText is present in an XML or not and to give an exception?

Posted by Damodar on Stack Overflow See other posts from Stack Overflow or by Damodar
Published on 2010-06-04T20:00:11Z Indexed on 2010/06/07 2:52 UTC
Read the original article Hit count: 289

Filed under:
|

Hey all,

I have written a code in C# - XML which checks whether a value is there or not in a given XML document and prints the value and the particular tag associated with the value. When we enter the Value of the Inner Text it will look for the value in the document and find it. I dont understand what exception to catch when the entered value is not there in the document.

I tried doing like this but it is not working.

1.

    if (inpXMLString != AppChildNode.InnerText)
    throw new InvalidDataException("The entered value" + " " + inpXMLString + " " + "doesnot exist");  

Here : inpXMLstring = entered value; AppChildNode.InnerText = value of the tags searched.

2.

      catch (System.Xml.XmlException e1)
      {
         Console.WriteLine(e1.Message);
      }

this does not give any exception when the entered value is not there in the XML document.

Please help me in this regard.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml