SAX2 RFD: LexicalHandler draft v.1.1

David Megginson david at megginson.com
Sun Mar 21 18:59:04 GMT 1999


James Clark writes:

 > David Megginson wrote:
 > 
 > >     public abstract void startEntity (String name)
 > >         throws SAXException;
 > > 
 > >     public abstract void endEntity (String name)
 > >         throws SAXException;
 > 
 > How does this allow me to find out about entity references in attribute
 > values (including defaulted attribute values)?

This is an interesting problem, and I was thinking about it last night 
while I was out walking my dog.  One possible solution is to extend
AttributeList to provide access to this information somehow (as we'll
be extending it, no doubt, to provide access to isSpecified
information).  Here's one alternative:

  public interface AttributeValueHandler
  {
    public abstract void startEntity (String name)
      throws SAXException;
    public abstract void endEntity (String name)
      throws SAXException;
    public abstract void characters (char ch[], int start, int length)
      throws SAXException;
  }

  public interface AttributeValue2 extends AttributeValue
  {
    public abstract boolean isSpecified (String name);
    public abstract void accept (AttributeValueHandler handler)
      throws SAXException;
  }

With this approach, the 99.9% of SAX applications that don't care
about entity boundaries within attribute values can continue to use
getValue() (which returns a literal string), while the others can use
AttributeValueHandler if the parser supports it -- of course, the
parser can throw a SAXNotSupportedException if it thinks that this
whole thing is too pathological.

 > It might be convenient to distinguish parameter entities and general
 > entities here.  The application can do this itself by maintaining the
 > appropriate state, but there doesn't seem any advantage in munging
 > together general and parameter entities.

There are two alternatives here:

1. Declare that PEs will always have '%' prepended to their names; or
2. add a boolean parameter isParameterEntity.

I'll add (2) for now.

 > How would general entity references in default attribute values in
 > attribute list declarations be handled?

Probably using a method similar to the one I specified above.  Now I
remember why I didn't want to cover DTD-related events in SAX...

 > Would all parameter entity references be reported or just those at the
 > top-level (ie between markup declarations)?

All, I'd imagine -- would there be a good reason for not doing so?

 > I don't think support for entities can be fully designed without also
 > considering DTD information.

Correct -- I apologise for my omitted note from earlier (which Lars
also caught).  I am assuming that there is already a mechanism for
reporting entity declarations.


All the best,


David

-- 
David Megginson                 david at megginson.com
           http://www.megginson.com/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list