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

Re: InnerXml is like printf (WAS: Underwhelmed)


whref
Miles Sabin <miles@m...> wrote:
| Arjun Ray wrote,

|> In what way could it be useful to produce fragments that are not 
|> well-formed?
| 
| Well formed ... but partial, so not conforming to the overall 
| DTD/schema. I suppose you could generate DTDs/schemas for fragments 
| from the overall DTD/schema too, but I have to wonder if the game's 
| really worth the candle.

Ah, okay, root element and all that.  I think we may have been talking at
slight cross-purposes.  

My main concern has always been well-formedness.  Validation is an extra
which I'm willing to forego in some circumstances, e.g. where the coders
do have familiarity with the vocabulary/ies.

DTDs, for instance, have no inherent notion of a root element (that's why
it's in the DOCTYPE declaration as a parameter): it's all a flat set of
declarations.  So, a "partial document" is still a legitimate document:

  <!DOCTYPE ul PUBLIC "-//W3C//DTD HTML Transitional 4.01//EN>
  <ul><li>An item</li></ul>

The only tricky part to the generation process would be whether you wanted
to enforce contextual dependencies (like, <li> within <ul> or <ol> only);
this would need more beef in the code generator.

But simple well-formedness is quite straightforward to guarantee.  People
who like to do things one at a time could code like this:

   HtmlFactory hf ;
   Visitor     printer ;
    
   Ehtml   eHtml   = hf.aHtml() ;
   Ehead   eHead   = hf.aHead() ;
   Etitle  eTitle  = hf.aTitle() ;
   (void)  eTitle  .add( "Example 1" ) ;
   (void)  eHead   .add( eTitle ) ;
   Elink   eLink   = hf.aLink() ;
   (void)  eLink   .wRel( "stylesheet" ) ;
   (void)  eLink   .wType( "text/css" ) ;
   (void)  eLink   .wHref( new Uri( "/ss/style.css" )) ;
   (void)  eHead   .add( eLink ) ;
   (void)  eHtml   .add( eHead ) ;
   Ebody   eBody   = hf.aBody() ;
   Ep      eP      = hf.aP() ;
   (void)  eP      .add( "Hello World!" ) ;
   (void)  eBody   .add( eP ) ;
   (void)  eHtml   .add( eBody ) ;
           eHtml   .accept( printer ) ;
  
The 17 operations could be done - but obviously need not - with no local
variables like this:

    hf.aHtml()
    .add( hf.aHead()
          .add( hf.aTitle()
                .add( "Example 2" ))
          .add( hf.aLink()
                .wRel("stylesheet")
                .wType("text/css") 
                .wHref(new Uri("/ss/style.css")) ))
    .add( hf.aBody()
          .add( hf.aP()
                .add( "Hello World!" )))
    .accept( printer ) ;

And you can even have convenience shortcuts (element constructors taking
content as an argument), allowing this:

    hf.aHtml( 
        hf.aHead( 
            hf.aTitle( "Example 3" )).add( 
            hf.aLink( )
                .wRel( "stylesheet" )
                .wType( "text/css" ) 
                .wHref( new Uri( "/ss/style.css" )))).add(
        hf.aBody( 
            hf.aP( "Hello World!" ))).accept( printer ) ;

Of course, doing things this way violates certain canons of established
Java "style", but the significant fact is that all strings and the like
are strictly data values only - all taxonomic names are internalized into
the syntax of the host environment, leveraging its own code validation
facilities.
 
For tag soup, there's a generic package (of the classes of which domain
specific library objects like above would be subclasses) which is only
slightly more verbose, making usage "difficult but not impossible", to
paraphrase Elliotte slightly.

Is it worth the candle?  I don't know.  I do know that people will try to
get away with as much as they can - until they learn the hard way that
they can't.
  

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.