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

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xml-dev] Handling internal general entities with SAX



At 3:46 PM -0700 2001-10-22, Rob Lugt wrote:
[text discussing defninition of "error" deleted...]
> 
> The issue Kurt raises reminds me of some thoughts I had when I
> first started looking into XML.  I wondered why parameter entities
> were so named, and concluded that it must be the intention that
> their value can be set by passing "parameters" to xml processors. 
> My mark-up experience doesn't stretch back to SGML, so I don't
> know if this was the original intention of parameter entities, but
> it certainly seems like a reasonable idea to me.
> 

Yup, that's basically it, except that it isn't (present tense, not
past tense) so much the passing of parameters from a command line as
much as it is simply the setting of parameters, regardless of where
or how they are set, so that they can be used later in the document.

Quoting from page 403 of "The SGML Handbook":

    When an external document type definition is used, the internal
    declaration subset can be used for two purposes:
    
     a) One use of the internal subset is to include modifications 
        or additions to the external DTD that will apply to this
        particular document.  That is typically done by declaring
        parameter entities in the internal subset that are the same
        as parameter entities in the external definition.  The
        declarations in the internal subset will take precedence
        because the internal subset is processed before the
        external.  (Remember, the external subset acts as if it is
        referenced at the end of the document type declaration.)
    
     b) The other use of the internal subset is to declare entities
        that are used only in this document.  It stretches the
        terminology a bit to think of such entities as part of the
        document type definition, but from a purely mechanical
        standpoint there is no real distinction...


> I haven't seen this behaviour in any xml processors but nsgmls
> comes close by being able to specify the -i{name} flag to change
> the replacement value of a parameter entity from "IGNORE" to
> "INCLUDE".
> 

Yeah, it's pretty handy, but like you, nsgmls is the only parser I
know of that has an option like that.

So that the stuff I'm working on works well with different parsers I
usually just use an environment variable for the server systems, or
a command-line argument that the shell scripts can use to select the
required set of PEs (different sets stored in different files).  It's
not rocket science and it doesn't come close to 100% buzzword
compliance but it works pretty well.

> If xml processors allowed applications to provide the replacement
> text for parameter entities at run time, then Kurt's original
> problem could be solved by declaring the "test" entity like so:-
> 
> <!ENTITY % param1 "[default]">
> <!ENTITY test "%param1;">
> 

While the XML processors themselves don't provide much support for
the selection or "early" declaration of parameter entities at run
time, a shell script or servlet can.

> As an illustration of the kind if thing I have in mind:-
> 
> XMLReader r = ...;
> r.setParameterEntity("param1", "replacement text");
> r.setParameterEntity("p2", "INCLUDE");
> p.parse("myfile.xml");
> 
> I know this facility isn't offered by SAX, but I wonder if it is
> possible using any of the native APIs?  Does anyone agree that
> this would be a useful feature to have?
> 

Hey, you could add a feature like nsgmls's -i option to ElCel's
products and achieve permanent lock-in of all users of those
products for the next 27 years.  Or, at the very least, it would 
be nice to have. 

Other makers of validating parsers, are you listening?

> One work-around that SAX does support right now is the ability to
> provide the replacement text for external entities.  So, if the
> test entity was declared as external like this:-
> 
> <!ENTITY test SYSTEM "get_the_test_entity">
> 
> then it would be relatively straight forward to write an
> EntityResolver that hooked into this and provided the appropriate
> replacement text via a StringReader.
> 
> 
> Regards
> ~Rob
> 
> --
> Rob Lugt
> ElCel Technology
> http://www.elcel.com/
> 
> 
[earlier quoted messages deleted...]


/s/ Ernest G. Allen
    Sunnyvale, CA, USA