how to check whether some entered InnerText is present in an XML or not and to give an exception?
- by Damodar
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.