简体   繁体   中英

What XML or JSON or ??? data format can describe a complex set of requirements?

I need to express

  • A passing grade in a pre-requite class, in order to access the next one.
  • An exemption policy to the above, where the professor can override the requirement.
  • A student can only have one such exemption in a given span of time (year)
  • Students must be older than 21
  • Students can only be enrolled in 3 eligible majors

Or similarly, the NY DMV has a complex set of documents and prerequisites in order to obtain a driver's license.

Question

  • What abstract syntax will allow me to describe the rules listed above, in a platform neutral way?

Use case

I'm developing an app where people define eligibility rules to access certain data. Those rules may have prerequisites, or key/value ranges to access it.

I am thinking XML, but that might become cumbersome. Just as swagger has become the "easier way" to handle web services, I'm looking for a similar "easy" syntax to handle these rules.

EDIT2: I have restructured my answer in order be more accurate...

The background of topic is actually entity–relationship management I think. I have not match to do with it... More on that topic: Entity–relationship model It seems to be a multi user issue where using a data base will help you out. Where you are able to define some access rights too. On the other hand in the real world this would be a server/client (cloud) scenario. On MS platform maybe Entity Framework... More on that topic: Entity Framework

Both format XML and JSON are pretty platform neutral.

If you choose XML then you are able to define some constraint using XSD and later on you can use it to validate the acquired data. Moreover you can use XSLT files to translate or represent you data many different ways.

You can find this link handy in order to understand the XML validation using XSD!

In order to be more specific we have to define some structure and experiment a little further. So let as experiment:

<Users>
  <User>
    <Identity ID="2015/PHY/S001201">
      <Name>My First Student</Name>
      <SomeOtherDetails/>
    </Identity>
    <Certificates>
      <Certificate ID="2015/PHY/M001/V01" Name="Math I.">
        <State>Finished</State>
        <Grade>Excellent</Grade>
        <Date>30.12.2015</Date>
      </Certificate>
      <Certificate ID="2015/PHY/M001/V01" Name="Math I.">
        <State>Finished</State>
      </Certificate>
    </Certificates>
  </User>
</Users>

So now we can create some rule:

<xsl:output method="xml" indent="yes" encoding ="utf-8"/>

<xsl:template match="/Users">
  <Result>
    <xsl:for-each select="./User">
      <xsl:apply-templates select="."/>
    </xsl:for-each>
  </Result>
</xsl:template>

<!-- This is my rule: user can apply only if he/she fills the requirements -->
<xsl:template match="User[ Certificates/Certificate/@ID = '2015/PHY/M001/V01' and Certificates/Certificate/State = 'Finished'  ]">
  <xsl:copy>
    <xsl:apply-templates select="Identity"/>
    <Course ID="2012/PHY/M002/V03">
      <Permission>Granted</Permission>
    </Course>
  </xsl:copy>
</xsl:template>

<xsl:template match="User"/>

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

Note : The actual match pattern has some error, was intend to illustrate the concept!

And here is the output:

<Result>
  <User>
    <Identity ID="2015/PHY/S001201">
      <Name>My First Student</Name>
      <SomeOtherDetails></SomeOtherDetails>
    </Identity>
    <Course ID="2012/PHY/M002/V03">
      <Permission>Granted</Permission>
    </Course>
  </User>
</Result>

So in general we have to describe the student and the professor with specific attributes.

Answer : So XML/XSLT for sure can express pretty complex data and conditions!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM