المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Validate XML file against rule in db



C# Programming
11-21-2012, 02:01 PM
Hi, I want to validate the xml file against certain set of rules in database.I have done most of the this but got stuck in below part. Any pointers will be appreciated.Following is the sample xml file. 1 Y 2 Y 3 Y 4 N 5 Y 1A Y As displayed there are multiple instances of tag. Now I have to validate below rule.

Rule 1- If QUES_NUMBER in (1,01,001) Then QUES_RESPONSE should be in (Y,N)
Rule 2- If QUES_RESPONSE Equals (Y) Then one instance of QUES_NUMBER 1A,01A,1B,01B should exist.
Rule 3- If QUES_NUMBER in (1A,01A) Then QUES_RESPONSE (X,Y,Z,Y/Z)
Rule 3.1- If QUES_NUMBER in (1B,01B) Then QUES_RESPONSE (X,Y,Z,Y/Z)

This is the complete Rule. If we are processing rule number 1 and result is true then we have to validate THEN condition (QUES_RESPONSE).
If THEN condition is true then I have to process Rule 2 (as there are multiple instance of same tag) I have to check the QUES_RESPONSE (Y)
of the same tag for which I have validated Rule 1 condition. For that purpose I am passing then index of index of the QUES_NUMBER and it works f9.
PROBLEM occurred in the THEN condition of Rule 2..Where are I am passing the value in xml file and match value (value in database Y,N) and index of the
question number to look at. But the as per then condition 1A..tag should exist and the code will try to locate the tag on that index which he will never
find.
Any pointer where I need to change in logic/any other way will be appreciated.
Below is the function which is validating the value in xml file against db value.
public static bool PROCESSRULE_RANGE(string expValue, ArrayList xmlValColl, out int valIndex)//, out Array avlValue { string currentValue = string.Empty; valIndex = -1; string[] expValArr = expValue.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); var intersect = expValArr.Intersect(xmlValColl.ToArray()); if (intersect.Count() > 0) { valIndex = xmlValColl.IndexOf(intersect.First()); return true; } }I am using XPATH to read the values in xml file.People Laugh on me Because i am Different but i Laugh on them
Because they all are same.