How to use regular expression validation for value at user defined XPAth in XML file?
If you want to check value at a particular XPath matches with regular expression provided by you , then you can use following code snippet. Code has been developed in C#. You can place this code in any .cs file and use the same.
User has to give input as XPath, regular expression and XML file which he wants to use for this match checking purpose.
Instead of using several methods for alphanumeric ,numeric , date checking regular expressions , user has to customize all in one single method.
Suppose your XML file is test1.xml and XPath in test1.xml is //students/student/First-name then user has to also specify which type of regular expression he wants to check against this mentioned XPath.
Lets say , user wants to apply alphanumeric regular expression then , he has to send input ^[a-zA-Z0-9]*$ for the parameter used for regular expression.