OpenSP provides a generic API in addition to its native API. The generic interface is much simpler than the native interface. It is generic in the sense that it could be easily implemented using parsers other than OpenSP. It provides all ESIS information as well as some other information about the instance that is commonly needed by applications. However, it doesn't provide access to all information available from OpenSP; in particular, it doesn't provide information about the DTD. It is also slightly less efficient than the native interface.
The interface uses two related abstract classes. An
SGMLApplication is an object that can handle a number of
different kinds of event which correspond to information in an SGML
document. An EventGenerator is an object that can
generate a sequence of events of the kinds handled by an
SGMLApplication. The
ParserEventGeneratorKit class makes an
EventGenerator that generates events using OpenSP.
SGMLApplication has a number of local types that are used
in several contexts:
Char
unsigned short if
SP_MULTI_BYTE is defined and unsigned char
otherwise.
CharString
Char.
It has the following members:
const Char *ptr
Chars of the string.
size_t len
Chars in the string.
Location
OpenEntityPtr
and a Position. The CharStrings in it will
remain valid as long as the OpenEntity that is pointed to
by the OpenEntityPtr that was used to construct it
remains valid.
It has the following members:
unsigned long lineNumber
(unsigned long)-1 if invalid.
unsigned long columnNumber
(unsigned long)-1 if invalid.
unsigned long byteOffset
(unsigned long)-1 if invalid.
unsigned long entityOffset
(unsigned long)-1 if invalid.
CharString entityName
CharString filename
const void *other
When a location is in an internal entity, the location of the reference to the entity will be used instead.
OpenEntity
OpenEntity is, in conjunction with a
Position, to create a Location. An
OpenEntity is accessed using an
OpenEntityPtr.
OpenEntityPtr
OpenEntity.
Position
Position is completely determined by the
OpenEntity object with which it is associated. The only
use for an Position is, in conjunction with an
OpenEntity, to create a Location.
ExternalId
bool haveSystemId
CharString systemId
havePublicId is true.
bool havePublicId
CharString publicId
havePublicId is true.
bool haveGeneratedSystemId
CharString generatedSystemId
haveGeneratedSystemId is true.
Notation
CharString name
ExternalId externalId
Entity
CharString name
Entity::DataType dataType
Entity::DataType is a local enum with the following possible
values:
Entity::sgml
Entity::cdata
Entity::sdata
Entity::ndata
Entity::subdoc
Entity::pi
Entity::DeclType declType
Entity::DeclType is a local enum with the following possible
values:
Entity::general
Entity::parameter
Entity::doctype
Entity::linktype
bool isInternal
CharString text
isInternal is true.
ExternalId externalId
isInternal is false.
const Attribute *attributes
isInternal is false.
size_t nAttributes
isInternal is false.
Notation notation
isInternal is false.
Attribute
CharString name
Attribute::Type type
Attribute::Type is a local type with the following possible
values:
Attribute::invalid
Attribute::implied
Attribute::cdata
Attribute::tokenized
Attribute::Defaulted defaulted
Attribute::Defaulted is a local enum with the following
possible values:
Attribute::specified
Attribute::definition
Attribute::current
size_t nCdataChunks
Attribute::CdataChunks comprising the value
of the attribute. Valid only if type is
cdata.
const Attribute::CdataChunk *cdataChunks
Attribute::CdataChunks comprising the value of this attribute.
Valid only if type is cdata.
Attribute::CdataChunk is a local struct with the
following members:
bool isSdata
CharString data
CharString entityName
isSdata is true.
This is non-ESIS information.
CharString tokens
type is Attribute::tokenized.
bool isId
size_t nEntities
const Entity *entities
Notation notation
For each event xyzEvent handled by
SGMLApplication, there is a virtual function of
SGMLApplication named xyz to
handle the event, and a local struct of SGMLApplication
named XyzEvent.
Pointers within an event xyzEvent are valid
only during the call to xyz. None of the
structs in events have copy constructors or assignment operators
defined. It is up to the event handling function to make a copy of
any data that it needs to preserve after the function returns.
Except as otherwise stated, the information in events is ESIS information. All position information is non-ESIS information.
There are the following types of event:
AppinfoEvent
Position pos
bool none
CharString string
none is false.
PiEvent
Position pos
CharString data
CharString entityName
StartElementEvent
Position pos
CharString gi
Element::ContentType contentType
Element::ContentType is an enum with the following
possible values:
Element::empty
Element::cdata
Element::rcdata
Element::mixed
Element::element
bool included
size_t nAttributes
const Attribute *attributes
EndElementEvent
Position pos
CharString gi
DataEvent
DataEvents.
The event has the following members:
Position pos
CharString data
SdataEvent
Position pos
CharString text
CharString entityName
ExternalDataEntityRefEvent
Position pos
Entity entity
SubdocEntityRefEvent
Position pos
Entity entity
StartDtdEvent
Position pos
CharString name
bool haveExternalId
ExternalId externalId
EndDtdEvent
Position pos
CharString name
EndPrologEvent
Position pos
GeneralEntityEvent
ParserEventGeneratorKit::outputGeneralEntities option is
enabled. This is non-ESIS information. The event has the following
members:
Entity entity
No event will be generated for the declaration of the
#default entity; instead an event will be generated when
an entity reference uses the #default entity if that is
the first time on which an entity with that name is used. This means
that GeneralEntityEvent can occur after the end of the
prolog.
CommentDeclEvent
ParserEventGeneratorKit::outputCommentDecls option is
enabled. This is non-ESIS information. The event has the following
members:
Position pos
size_t nComments
const CharString *comments
const CharString *seps
MarkedSectionStartEvent
ParserEventGeneratorKit::outputMarkedSections
option is enabled.
This is non-ESIS information.
The event has the following members:
Position pos
MarkedSectionStartEvent::Status status
MarkedSectionStartEvent::Status is a local enum with the
following possible values:
MarkedSectionStartEvent::include
MarkedSectionStartEvent::rcdata
MarkedSectionStartEvent::cdata
MarkedSectionStartEvent::ignore
size_t nParams
const MarkedSectionStartEvent::Param *params
Param is a local struct with the following members:
MarkedSectionStartEvent::Param::Type type
MarkedSectionStartEvent::Param::Type is a local enum with the
following possible values:
MarkedSectionStartEvent::Param::temp
MarkedSectionStartEvent::Param::include
MarkedSectionStartEvent::Param::rcdata
MarkedSectionStartEvent::Param::cdata
MarkedSectionStartEvent::Param::ignore
MarkedSectionStartEvent::Param::entityRef
CharString entityName
type is
MarkedSectionStartEvent::Param::entityRef.
MarkedSectionEndEvent
ParserEventGeneratorKit::outputMarkedSections option is
enabled. This is non-ESIS information. The event has the following
members:
Position pos
MarkedSectionEndEvent::Status status
MarkedSectionEndEvent::Status is a local enum with the
following possible values:
MarkedSectionEndEvent::include
MarkedSectionEndEvent::rcdata
MarkedSectionEndEvent::cdata
MarkedSectionEndEvent::represents a currently open entity. The only use for an
OpenEntity is, in conjunction with a
Position, to create a Location. An
OpenEntity is accessed using an
OpenEntityPtr.
-
OpenEntityPtr
-
This class is a reference-counted pointer to an
OpenEntity.
-
Position
-
This is an integral type that represents a position in an open entity.
The meaning of a
Position is completely determined by the
OpenEntity object with which it is associated. The only
use for an Position is, in conjunction with an
OpenEntity, to create a Location.
-
ExternalId
-
This struct represents an external identifier. It has the following
members:
-
bool haveSystemId
-
True iff the external identifier included an explicit system identifier.
-
CharString systemId
-
The system identifier included in the external identifier.
Valid only if
havePublicId is true.
-
bool havePublicId
-
True iff the external identifier included an explicit public identifier.
-
CharString publicId
-
The public identifier included in the external identifier.
Valid only if
havePublicId is true.
-
bool haveGeneratedSystemId
-
True iff a system identifier was generated for the external identifier.
-
-
CharString generatedSystemId
-
The system identifier generated for the external identifier.
Valid only if
haveGeneratedSystemId is true.
-
Notation
-
This struct represents a notation.
It has the following members:
-
CharString name
-
The name of the notation.
-
ExternalId externalId
-
The external identifier of the notation.
-
Entity
-
This struct represents an entity.
It has the following members.
-
CharString name
-
The name of the entity.
-
Entity::DataType dataType
-
The type of the data of the entity.
Entity::DataType is a local enum with the following possible
values:
-
Entity::sgml
-
-
Entity::cdata
-
-
Entity::sdata
-
-
Entity::ndata
-
-
Entity::subdoc
-
-
Entity::pi
-
-
Entity::DeclType declType
-
The type of the declaration of the entity.
Entity::DeclType is a local enum with the following possible
values:
-
Entity::general
-
The entity is a general entity.
-
Entity::parameter
-
The entity is a parameter entity.
-
Entity::doctype
-
The entity was declared in a doctype declaration.
-
Entity::linktype
-
The entity was declared in a linktype declaration.
-
bool isInternal
-
True iff the entity is internal rather than external.
-
CharString text
-
The replacement text of the entity.
Valid only if
isInternal is true.
-
ExternalId externalId
-
The external identifier of the entity.
Valid only if
isInternal is false.
-
const Attribute *attributes
-
Pointer to the data attributes of the entity.
Valid only if
isInternal is false.
-
size_t nAttributes
-
The number of data attributes of the entity.
Valid only if
isInternal is false.
-
Notation notation
-
The entity's notation.
An empty string if the entity has no notation.
Valid only if
isInternal is false.
-
Attribute
-
This struct represents an attribute. More precisely it represents the
assignment of an attribute value to an attribute name.
It has the following members:
-
CharString name
-
The attribute name.
-
Attribute::Type type
-
An enumeration describing the type of the attribute.
Attribute::Type is a local type with the following possible
values:
Attribute::invalid
-
The attribute is invalid.
Attribute::implied
-
The attribute is an impliable attribute for which
no value was specified.
Attribute::cdata
-
The attribute is a CDATA attribute.
Attribute::tokenized
-
The attribute is a tokenized attribute.
-
Attribute::Defaulted defaulted
-
An enumeration specifying whether the entity was defaulted, and, if
so, how.
This is non-ESIS information.
Attribute::Defaulted is a local enum with the following
possible values:
-
Attribute::specified
-
The value was explicitly specified.
-
Attribute::definition
-
The value was defaulted from the attribute definition.
-
Attribute::current
-
The value was defaulted using the CURRENT value of the attribute.
-
size_t nCdataChunks
-
The number of
Attribute::CdataChunks comprising the value
of the attribute. Valid only if type is
cdata.
-
const Attribute::CdataChunk *cdataChunks
-
The
Attribute::CdataChunks comprising the value of this attribute.
Valid only if type is cdata.
Attribute::CdataChunk is a local struct with the
following members:
-
bool isSdata
-
True iff this chunk is the replacement text of an internal SDATA entity.
-
CharString data
-
The data of this chunk.
-
CharString entityName
-
The name of the internal SDATA entity that this chunk is the
replacement text of. Valid only if
isSdata is true.
This is non-ESIS information.
-
CharString tokens
-
Valid only if
type is Attribute::tokenized.
-
bool isId
-
True iff the declared value is ID.
This is non-ESIS information.
-
size_t nEntities
-
The number of entities associated with this attribute.
This will be zero unless the declared value is ENTITY or ENTITIES.
-
const Entity *entities
-
The entities associated with this attribute.
-
Notation notation
-
The notation associated with this attribute.
If the declared value of the attribute is not NOTATION,
then the name member will be an empty string.
For each event xyzEvent handled by
SGMLApplication, there is a virtual function of
SGMLApplication named xyz to
handle the event, and a local struct of SGMLApplication
named XyzEvent.
Pointers within an event xyzEvent are valid
only during the call to xyz. None of the
structs in events have copy constructors or assignment operators
defined. It is up to the event handling function to make a copy of
any data that it needs to preserve after the function returns.
Except as otherwise stated, the information in events is ESIS information. All position information is non-ESIS information.
There are the following types of event:
AppinfoEvent
Position pos
bool none
CharString string
none is false.
PiEvent
Position pos
CharString data
CharString entityName
StartElementEvent
Position pos
CharString gi
Element::ContentType contentType
Element::ContentType is an enum with the following
possible values:
Element::empty
Element::cdata
Element::rcdata
Element::mixed
Element::element
bool included
size_t nAttributes
const Attribute *attributes
EndElementEvent