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

Re: is rng compact, compact enough?


td class text
Bill de hÓra wrote:

> Playing about with RNG compact syntax, I've come to the conclusion that 
> it's to harder to read than the XML syntax.

There are ways to write it that are readable and ways to write it that 
are not so readable. The style that's most readable in one syntax isn't 
necessarily most readable in the other syntax. In my experience, real 
world schemas tend to make very heavy use of definitions/references, 
partly for modularity and partly because with RELAX NG, as with DTDs, 
redefinition is the main customization mechanism.  If you look at 
Docbook for example, the number of <ref> elements is much greater than 
the number of <element> elements. For this reason, RELAX NG compact 
syntax was designed to optimize the readability of schemas that use 
definitions/references heavily.  The examples in the compact syntax 
tutorial were automatically translated (by trang) from the examples in 
the XML syntax tutorial and haven't been optimized for readability in 
the compact syntax (this should probably be fixed).

> Consider the + quantifier below:
> 
> element html {
>   element head {
>     element title { text }
>   },
>   element body {
>     element table {
>       attribute class { "addressBook" },
>       element tr {
>         attribute class { "card" },
>         element td {
>           attribute class { "name" },
>           mixed {
>             element span {
>               attribute class { "givenName" },
>               text
>             }?,
>             element span {
>               attribute class { "familyName" },
>               text
>             }?
>           }
>         },
>         element td {
>           attribute class { "email" },
>           text
>         }
>       }+
>     }
>   }
> }
> 
> when you could have this:
> 
> 
> element html {
>   element head {
>     element title { text }
>   },
>   element body {
>     element table {
>       attribute class { "addressBook" },
>       element+ tr {
>         attribute class { "card" },
>         element td {
>           attribute class { "name" },
>           mixed {
>             element? span {
>               attribute class { "givenName" },
>               text
>             },
>             element? span {
>               attribute class { "familyName" },
>               text
>             }
>           }
>         },
>         element td {
>           attribute class { "email" },
>           text
>         }
>       }
>     }
>   }
> }

The quantifier after the keyword is an interesting idea, but it weakens 
the similarity to normal regular expressions.  And the example still 
isn't all that readable. A better solution is to use a style more 
suitable for the compact syntax.  I would probably write it something 
like this:

start = html
html = element html { head, body }
head = element head { title }
title = element title { text }
body = element body { addressBook }
addressBook = element table { addressBook.class, card+ }
card = element tr { card.class, name, email }
name = element td { name.class, mixed { givenName?, familyName? } }
givenName = element span { givenName.class, text }
familyName = element span { familyName.class, text }
email = element td { email.class, text }
addressBook.class = attribute class { "addressBook" }
card.class = attribute class { "card" }
name.class = attribute class { "name" }
givenName.class = attribute class { "givenName" }
familyName.class = attribute class { "familyName" }
email.class = attribute class { "email" }

> Also, attributes don't need to be bracketed; by nature they don't have 
> any structure on the rhs. 

Although an attribute cannot contain attributes or elements, the pattern 
for the value of an attribute can be quite complex:

attribute value {
   list { xsd:int { minInclusive = "0" maxInclusive = "100" }+ }
   | "#none"
}

James







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.