How to check whether a expected element value length is present in the value of given XPath of XML
There is a sample code to check whether any expected element value length is present in XPath in xml file or not. User can set xpath , expected element value length and xml file dynamically to check this. Code has been developed in C# whereas application is windows based.
Introduction
I have developed the method which will give you true as a result if expected element value length is present in the XPath of XML file. If that expected element value length is not present in xpath of xml file then it will give false as a result.
User has to give parameters as xpathvalue , xml file path , expected element value length in the method.
Description
Create a class library in which put this code snippet and call whenever it is required.
public bool Match_element_value_length (string user_defined_xpath, string user_defined_xml_file, string user_defined_expected_length)
{
bool result_val = false;
XmlDocument user_defined_xml_doc = new XmlDocument();
user_defined_xml_doc.Load(user_defined_xml_file);
XmlNodeList my_nodeList = user_defined_xml_doc.SelectNodes(user_defined_xpath);
foreach (XmlNode my_node in my_nodeList)
{
if (Convert.ToString(my_node.InnerText.Length) == user_defined_expected_length)
{
result_val = true;
return result_val;
}
else
{
result_val = false;
}
}
return result_val;
}