[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: is rng compact, compact enough?
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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|