Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Validate XML file against rule in db

Validate XML file against rule in db

Scheduled Pinned Locked Moved C#
databasehelpregexxmlquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahul net11
    wrote on last edited by
    #1

    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.

    <BACKGROUND>
    <QUES_NUMBER>1</QUES_NUMBER>
    <QUES_RESPONSE>Y</QUES_RESPONSE>
    </BACKGROUND>
    <BACKGROUND>
    <QUES_NUMBER>2</QUES_NUMBER>
    <QUES_RESPONSE>Y</QUES_RESPONSE>
    </BACKGROUND>
    <BACKGROUND>
    <QUES_NUMBER>3</QUES_NUMBER>
    <QUES_RESPONSE>Y</QUES_RESPONSE>
    </BACKGROUND>
    <BACKGROUND>
    <QUES_NUMBER>4</QUES_NUMBER>
    <QUES_RESPONSE>N</QUES_RESPONSE>
    </BACKGROUND>
    <BACKGROUND>
    <QUES_NUMBER>5</QUES_NUMBER>
    <QUES_RESPONSE>Y</QUES_RESPONSE>
    </BACKGROUND>
    <BACKGROUND>
    <QUES_NUMBER>1A</QUES_NUMBER>
    <QUES_RESPONSE>Y</QUES_RESPONSE>
    </BACKGROUND>

    As displayed there are multiple instances of <BACKGROUND><QUES_NUMBER><QUES_RESPONSE></BACKGROUND> 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 fil

    P 1 Reply Last reply
    0
    • R rahul net11

      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.

      <BACKGROUND>
      <QUES_NUMBER>1</QUES_NUMBER>
      <QUES_RESPONSE>Y</QUES_RESPONSE>
      </BACKGROUND>
      <BACKGROUND>
      <QUES_NUMBER>2</QUES_NUMBER>
      <QUES_RESPONSE>Y</QUES_RESPONSE>
      </BACKGROUND>
      <BACKGROUND>
      <QUES_NUMBER>3</QUES_NUMBER>
      <QUES_RESPONSE>Y</QUES_RESPONSE>
      </BACKGROUND>
      <BACKGROUND>
      <QUES_NUMBER>4</QUES_NUMBER>
      <QUES_RESPONSE>N</QUES_RESPONSE>
      </BACKGROUND>
      <BACKGROUND>
      <QUES_NUMBER>5</QUES_NUMBER>
      <QUES_RESPONSE>Y</QUES_RESPONSE>
      </BACKGROUND>
      <BACKGROUND>
      <QUES_NUMBER>1A</QUES_NUMBER>
      <QUES_RESPONSE>Y</QUES_RESPONSE>
      </BACKGROUND>

      As displayed there are multiple instances of <BACKGROUND><QUES_NUMBER><QUES_RESPONSE></BACKGROUND> 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 fil

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      What occurs to me is the possibility of having the rules be XPath expressions. For example, rule 1 could be expressed as something like: //BACKGROUND/QUES_NUMBER[.='1' or .='01' or .='001']/parent::BACKGROUND/QUES_RESPONSE[.='Y' or .='N'] These expressions could then be stored in the database, probably with something to indicate which order to apply them and a value (e.g. 0 or 1) that would indicate a successful test. Maybe have a branching scheme -- so you can choose the next rules based on the result of the current one. For instance, the above expression should return one node -- if 0 fail, if 1 goto rule 2, else fail. However, it will be very tricky to define the rules exactly right.

      R 1 Reply Last reply
      0
      • P PIEBALDconsult

        What occurs to me is the possibility of having the rules be XPath expressions. For example, rule 1 could be expressed as something like: //BACKGROUND/QUES_NUMBER[.='1' or .='01' or .='001']/parent::BACKGROUND/QUES_RESPONSE[.='Y' or .='N'] These expressions could then be stored in the database, probably with something to indicate which order to apply them and a value (e.g. 0 or 1) that would indicate a successful test. Maybe have a branching scheme -- so you can choose the next rules based on the result of the current one. For instance, the above expression should return one node -- if 0 fail, if 1 goto rule 2, else fail. However, it will be very tricky to define the rules exactly right.

        R Offline
        R Offline
        rahul net11
        wrote on last edited by
        #3

        Hi, Thanks for your reply.. Now the problem has been resolved... Rahul

        People Laugh on me Because i am Different but i Laugh on them Because they all are same.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups