[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Which is more declarative? More XMLish?

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Sat, 2 Dec 2017 14:26:36 +0000

Which is more declarative? More XMLish?

Hi Folks,

XML documents oftentimes contain a set of things – a set of books, a set of people, a set of transactions, etc.

Typically, a set isn’t allowed to contain just anything, the set must satisfy some constraints.

Constraints can be expressed in different ways. Perhaps one way is better than another? Perhaps one is more declarative, the other more imperative? Perhaps one is XMLish, the other not?

Example: Here is an XML document containing a set (of positive even numbers):

<numbers>
   
<number>0</number>
   
<number>2</number>
   
<number>4</number>
   
<number>6</number>

    …
</numbers>

 

Here are two ways to specify the set:

 

1. Defining properties: identify the properties that each member of the set must have. In this example, each number must have these 2 properties:

 

  • Positivity
  • Evenness

 

The two properties can be expressed in Schematron:

 

<sch:rule context="number">
   
    
<sch:assert test="xs:integer(.) ge 0">
        Property: to be a member of the set, the number must be positive.
   
</sch:assert>
   
    
<sch:assert test="xs:integer(.) mod 2 eq 0">
        Property: to be a member of the set, the number must be even.
   
</sch:assert>


</sch:rule>

 

2. Generate set members: specify how to generate the members of the set. The set of positive even numbers can be generated this way:

 

  1. 0 is an element of the set.
  2. If x is an element of the set, then x+2 is an element of the set. (Alternatively: if x is an element of the set, then x-2 is an element of the set)
  3. Nothing else belongs to the set.

 

Generating the set’s members can be expressed in Schematron:

 

<sch:rule context="numbers">
   
    
<sch:assert test="number[xs:integer(.) eq 0]">
        0 is in the set.
   
</sch:assert>
   
    
<sch:assert test="every $i in number[xs:integer(.) ne 0] satisfies
                                    number[xs:integer(.) eq ($i - 2)]"
>
        If i is in the set, then i-2 is in the set
   
</sch:assert>
   
</sch:rule>

 

Recap: We’ve seen two ways to specify (constrain) a set:

(a) State a property (or properties) that an object must have to qualify as a member of the set.

(b) Define a set of rules which generate its members.

 

Which way is better? Which is preferred? Which is more declarative? Which is more XMLish?

 

/Roger



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.