[XMLDEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Which is more declarative? More XMLish?
Hi Roger, > 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> This is not a set  this is, strictly speaking, a sequence. More precisely, this is just one of the n! possible representations of the set {0, 2, ..., 2*(n1)} as a specific sequence. I believe in XML Schema there is a way to express that the order of elements doesn't matter  this must be specified when defining a set. > <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> The above rule describes all possible sets of even, nonnegative numbers. In particular, it also describes the infinite set of all such numbers. But an XML document cannot contain infinite number of elements (unless W3C makes a new XML Spec allowing this  and this would be conveniently handinhand with XSLT streaming). But again, a rule for infinite number of elements cannot be validated in finite time... Therefore, new schema language constructs are needed when streaming a document. And the validation of documents while streaming could be something like "Dynamic" or "Samplebased" validation. Note: even XML wellformedness cannot be validated when streaming a document. This means that any serious XML streaming must be performed in transactional manner. Cheers, Dimitre On Sat, Dec 2, 2017 at 6:26 AM, Costello, Roger L. <costello@mitre.org> wrote: > 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: > > > > 0 is an element of the set. > 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 x2 is an element of the > set) > 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 i2 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  Cheers, Dimitre Novatchev  Truly great madness cannot be achieved without significant intelligence.  To invent, you need a good imagination and a pile of junk  Never fight an inanimate object  To avoid situations in which you might make mistakes may be the biggest mistake of all  Quality means doing it right when no one is looking.  You've achieved success in your field when you don't know whether what you're doing is work or play  To achieve the impossible dream, try going to sleep.  Facts do not cease to exist because they are ignored.  Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :)  Sanity is madness put to good use.  I finally figured out the only reason to be alive is to enjoy it.
[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! Download The World's Best XML IDE!Accelerate XML development with our awardwinning XML IDE  Download a free trial today! Subscribe in XML format
