[
Lists Home |
Date Index |
Thread Index
]
- From: Wayne Steele <xmlmaster@hotmail.com>
- To: xml-dev@lists.xml.org
- Date: Mon, 30 Oct 2000 11:12:28 -0800 (PST)
Actually, I have been using Schematron recently for just this kind of thing.
I would have included that in my list, but I was trying to stay inside the
"DTD Box". Other choices to investigate might be XDR, Relax, or just writing
your own code to grovel over the DOM.
Schematron is pretty cool.
Thanks Rick.
-Wayne Steele
>From: Rick JELLIFFE <ricko@geotempo.com>
>To: xml-dev@lists.xml.org
>Subject: Re: Must DTDs constrain order?
>Date: Sun, 29 Oct 2000 16:07:03 +0800
>
>Wayne Steele wrote:
> >
> > I have had to deal with this frequently.
> > Here are several choices I've made at different times:
> >
> > 1. Express the {baz,bar,bang} information using attributes instead of
> > elements.
> >
> > 2. As Soumitra said, use <!ELEMENT foo (bar | bat | bang)*>
> > I would put a comment next to this, as well:
> > <!-- no more than one of each of these, in any order -->
> >
> > 3. Do the combinatorial explosion yourself. You would probably also
>want
> > to include a comment so human DTD readers can figure out what's going on
> > without too much pain.
> > <!-- foo must contain one of each of {bar,baz,bang} in any order -->
> > <!ELEMENT foo (
> > (bar, ((baz,bang)|(bang,baz)) ) |
> > (baz, ((bar,bang)|(bang,bar)) ) |
> > (bang,((bar,baz) |(baz,bar)) )
> > ) >
> >
> > 4. Use SGML instead of XML for this application, and use "&".
> >
> > Ha Ha! Ok, I've never actually used SGML outside of XML. I was just
>kidding.
>
>You may find SGML easier than you think. XML was designed to be small.
>Don't be surprised when you find examples that are too big for it
>
>Given that XML DTDs are a little tedious for this, and that XML Schemas
>may be overkill, you might consider using Schematron schemas. These
>simply make assertions using XPaths rather than trying to squeeze what
>you need into a regular grammar.
>
>For example, for the example above, here is the Schematron schema
>fragment that does the job. (To understand the example, it may help to
>know that the context is an XPath expressions, and the test is an XSLT
>expression which is evaluated in that context: so "bar" in a test means,
>"bar, the child of foo".)
>
> <rule context="foo">
> <assert test="count(bar)=1" >A foo must have one bar</assert>
> <assert test="count(bat) < 2">A foo may have 0 or 1
>bat</assert>
> <assert test="count(*)=count(bar)+count(bat)+count(bang)"
> >A foo may only contain bar, bat and bang elements</assert>
> </rule>
>
>The schematron site is currently
> http://www.ascc.net/xml/resource/schematron/schematron.html
>
>(We are currently upgrading it to prepare for the move to Source Forge
>real soon, and site maintenance at Academia Sinica means it is off the
>air this weekend.)
>
>Cheers
>Rick Jelliffe
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
|