OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] InnerXml is like printf (WAS: Underwhelmed)

[ Lists Home | Date Index | Thread Index ]

Miles Sabin <miles@milessabin.com> 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.
  




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS