home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_70107d902c451c5e62691276628a3431
< prev
next >
Wrap
Text File
|
2000-03-23
|
19KB
|
394 lines
<HTML>
<HEAD>
<TITLE>SGMLS - class for postprocessing the output from the B<sgmls> and
B<nsgmls> parsers.</TITLE>
<LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> SGMLS - class for postprocessing the output from the B<sgmls> and
B<nsgmls> parsers.</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<UL>
<LI><A HREF="#the sgmls class">The <CODE>SGMLS</CODE> class</A></LI>
<LI><A HREF="#the sgmls_event class">The <CODE>SGMLS_Event</CODE> class</A></LI>
<LI><A HREF="#the sgmls_element class">The <CODE>SGMLS_Element</CODE> class</A></LI>
<LI><A HREF="#the sgmls_attribute class">The <CODE>SGMLS_Attribute</CODE> class</A></LI>
<LI><A HREF="#the sgmls_notation class">The <CODE>SGMLS_Notation</CODE> class</A></LI>
<LI><A HREF="#the sgmls_entity class">The <CODE>SGMLS_Entity</CODE> class</A></LI>
</UL>
<LI><A HREF="#author and copyright">AUTHOR AND COPYRIGHT</A></LI>
<LI><A HREF="#see also:">SEE ALSO:</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>SGMLS - class for postprocessing the output from the <STRONG>sgmls</STRONG> and
<STRONG>nsgmls</STRONG> parsers.</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use SGMLS;</PRE>
<PRE>
my $parse = new SGMLS(STDIN);</PRE>
<PRE>
my $event = $parse->next_event;
while ($event) {</PRE>
<PRE>
SWITCH: {</PRE>
<PRE>
($event->type eq 'start_element') && do {
my $element = $event->data; # An object of class SGMLS_Element
[[your code for the beginning of an element]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'end_element') && do {
my $element = $event->data; # An object of class SGMLS_Element
[[your code for the end of an element]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'cdata') && do {
my $cdata = $event->data; # A string
[[your code for character data]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'sdata') && do {
my $sdata = $event->data; # A string
[[your code for system data]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 're') && do {
[[your code for a record end]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'pi') && do {
my $pi = $event->data; # A string
[[your code for a processing instruction]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'entity') && do {
my $entity = $event->data; # An object of class SGMLS_Entity
[[your code for an external entity]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'start_subdoc') && do {
my $entity = $event->data; # An object of class SGMLS_Entity
[[your code for the beginning of a subdoc entity]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'end_subdoc') && do {
my $entity = $event->data; # An object of class SGMLS_Entity
[[your code for the end of a subdoc entity]]
last SWITCH;
};</PRE>
<PRE>
($event->type eq 'conforming') && do {
[[your code for a conforming document]]
last SWITCH;
};</PRE>
<PRE>
die "Internal error: unknown event type " . $event->type . "\n";
}</PRE>
<PRE>
$event = $parse->next_event;
}</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>The <STRONG>SGMLS</STRONG> package consists of several related classes: see
<A HREF="#sgmls">SGMLS</A>, <A HREF="#sgmls_event">SGMLS_Event</A>, <A HREF="#sgmls_element">SGMLS_Element</A>,
<A HREF="#sgmls_attribute">SGMLS_Attribute</A>, <A HREF="#sgmls_notation">SGMLS_Notation</A>, and <A HREF="#sgmls_entity">SGMLS_Entity</A>. All
of these classes are available when you specify</P>
<PRE>
use SGMLS;</PRE>
<P>Generally, the only object which you will create explicitly will
belong to the <CODE>SGMLS</CODE> class; all of the others will then be created
automatically for you over the course of the parse. Much fuller
documentation is available in the <CODE>.sgml</CODE> files in the <CODE>DOC/</CODE>
directory of the <CODE>SGMLS.pm</CODE> distribution.</P>
<P>
<H2><A NAME="the sgmls class">The <CODE>SGMLS</CODE> class</A></H2>
<P>This class holds a single parse. When you create an instance of it,
you specify a file handle as an argument (if you are reading the
output of <STRONG>sgmls</STRONG> or <STRONG>nsgmls</STRONG> from a pipe, the file handle will
ordinarily be <CODE>STDIN</CODE>):</P>
<PRE>
my $parse = new SGMLS(STDIN);</PRE>
<P>The most important method for this class is <A HREF="#item_next_event"><CODE>next_event</CODE></A>, which reads
and returns the next major event from the input stream. It is
important to note that the <CODE>SGMLS</CODE> class deals with most <STRONG>ESIS</STRONG>
events itself: attributes and entity definitions, for example, are
collected and stored automatically and invisibly to the user. The
following list contains all of the methods for the <CODE>SGMLS</CODE> class:</P>
<DL>
<DT><STRONG><A NAME="item_next_event"><CODE>next_event()</CODE>: Return an <CODE>SGMLS_Event</CODE> object containing the
next major event from the SGML parse.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_element"><CODE>element()</CODE>: Return an <CODE>SGMLS_Element</CODE> object containing the
current element in the document.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_file"><CODE>file()</CODE>: Return a string containing the name of the current
SGML source file (this will work only if the <CODE>-l</CODE> option was given to
<STRONG>sgmls</STRONG> or <STRONG>nsgmls</STRONG>).</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_line"><CODE>line()</CODE>: Return a string containing the current line number
from the source file (this will work only if the <CODE>-l</CODE> option was
given to <STRONG>sgmls</STRONG> or <STRONG>nsgmls</STRONG>).</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_appinfo"><CODE>appinfo()</CODE>: Return a string containing the <CODE>APPINFO</CODE>
parameter (if any) from the SGML declaration.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_notation"><CODE>notation(NNAME)</CODE>: Return an <CODE>SGMLS_Notation</CODE> object
representing the notation named <CODE>NNAME</CODE>. With newer versions of
<STRONG>nsgmls</STRONG>, all notations are available; otherwise, only the notations
which are actually used will be available.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_entity"><CODE>entity(ENAME)</CODE>: Return an <CODE>SGMLS_Entity</CODE> object representing
the entity named <CODE>ENAME</CODE>. With newer versions of <STRONG>nsgmls</STRONG>, all
entities are available; otherwise, only external data entities and
internal entities used as attribute values will be available.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_ext"><CODE>ext()</CODE>: Return a reference to an associative array for
user-defined extensions.</A></STRONG><BR>
<DD>
</DL>
<P>
<H2><A NAME="the sgmls_event class">The <CODE>SGMLS_Event</CODE> class</A></H2>
<P>This class holds a single major event, as generated by the
<A HREF="#item_next_event"><CODE>next_event</CODE></A> method in the <CODE>SGMLS</CODE> class. It uses the following
methods:</P>
<DL>
<DT><STRONG><A NAME="item_type"><CODE>type()</CODE>: Return a string describing the type of event:
``start_element'', ``end_element'', ``cdata'', ``sdata'', ``re'', ``pi'',
``entity'', ``start_subdoc'', ``end_subdoc'', and ``conforming''. See
<A HREF="#synopsis">SYNOPSIS</A>, above, for the values associated with each of these.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_data"><CODE>data()</CODE>: Return the data associated with the current event (if
any). For ``start_element'' and ``end_element'', returns an
<CODE>SGMLS_ELement</CODE> object; for ``entity'', ``start_subdoc'', and
``end_subdoc'', returns an <CODE>SGMLS_Entity</CODE> object; for ``cdata'', ``sdata'',
and ``pi'', returns a string; and for ``re'' and ``conforming'', returns the
empty string. See <A HREF="#synopsis">SYNOPSIS</A>, above, for an example of this
method's use.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_key"><CODE>key()</CODE>: Return a string key to the event, such as an element
or entity name (otherwise, the same as <A HREF="#item_data"><CODE>data()</CODE></A>).</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>file()</CODE>: Return the current file name, as in the <CODE>SGMLS</CODE>
class.</STRONG><BR>
<DD>
<DT><STRONG><CODE>line()</CODE>: Return the current line number, as in the <CODE>SGMLS</CODE>
class.</STRONG><BR>
<DD>
<DT><STRONG><CODE>element()</CODE>: Return the current element, as in the <CODE>SGMLS</CODE>
class.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_parse"><CODE>parse()</CODE>: Return the <CODE>SGMLS</CODE> object which generated the
event.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>entity(ENAME)</CODE>: Look up an entity, as in the <CODE>SGMLS</CODE> class.</STRONG><BR>
<DD>
<DT><STRONG><CODE>notation(ENAME)</CODE>: Look up a notation, as in the <CODE>SGMLS</CODE>
class.</STRONG><BR>
<DD>
<DT><STRONG><CODE>ext()</CODE>: Return a reference to an associative array for
user-defined extensions.</STRONG><BR>
<DD>
</DL>
<P>
<H2><A NAME="the sgmls_element class">The <CODE>SGMLS_Element</CODE> class</A></H2>
<P>This class is used for elements, and contains all associated
information (such as the element's attributes). It recognises the
following methods:</P>
<DL>
<DT><STRONG><A NAME="item_name"><CODE>name()</CODE>: Return a string containing the name, or Generic
Identifier, of the element, in upper case.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_parent"><CODE>parent()</CODE>: Return the <CODE>SGMLS_Element</CODE> object for the
element's parent (if any).</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>parse()</CODE>: Return the <CODE>SGMLS</CODE> object for the current parse.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_attributes"><CODE>attributes()</CODE>: Return a reference to an associative array of
attribute names and <CODE>SGMLS_Attribute</CODE> structures. Attribute names
will be all in upper case.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_attribute_names"><CODE>attribute_names()</CODE>: Return an array of strings containing the
names of all attributes defined for the current element, in upper
case.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_attribute"><CODE>attribute(ANAME)</CODE>: Return the <CODE>SGMLS_Attribute</CODE> structure for
the attribute <CODE>ANAME</CODE>.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_set_attribute"><CODE>set_attribute(ATTRIB)</CODE>: Add the <CODE>SGMLS_Attribute</CODE> object
<CODE>ATTRIB</CODE> to the current element, replacing any other attribute
structure with the same name.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_in"><CODE>in(GI)</CODE>: Return <CODE>true</CODE> (ie. 1) if the string <CODE>GI</CODE> is the
name of the current element's parent, or <CODE>false</CODE> (ie. 0) if it is
not.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_within"><CODE>within(GI)</CODE>: Return <CODE>true</CODE> (ie. 1) if the string <CODE>GI</CODE> is the
name of any of the ancestors of the current element, or <CODE>false</CODE>
(ie. 0) if it is not.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>ext()</CODE>: Return a reference to an associative array for
user-defined extensions.</STRONG><BR>
<DD>
</DL>
<P>
<H2><A NAME="the sgmls_attribute class">The <CODE>SGMLS_Attribute</CODE> class</A></H2>
<P>Each instance of an attribute for each <CODE>SGMLS_Element</CODE> is an object
belonging to this class, which recognises the following methods:</P>
<DL>
<DT><STRONG><CODE>name()</CODE>: Return a string containing the name of the current
attribute, all in upper case.</STRONG><BR>
<DD>
<DT><STRONG><CODE>type()</CODE>: Return a string containing the type of the current
attribute, all in upper case. Available types are ``IMPLIED'', ``CDATA'',
``NOTATION'', ``ENTITY'', and ``TOKEN''.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_value"><CODE>value()</CODE>: Return the value of the current attribute, if any.
This will be an empty string if the type is ``IMPLIED'', a string of
some sort if the type is ``CDATA'' or ``TOKEN'' (if it is ``TOKEN'', you may
want to split the string into a series of separate tokens), an
<CODE>SGMLS_Notation</CODE> object if the type is ``NOTATION'', or an
<CODE>SGMLS_Entity</CODE> object if the type is ``ENTITY''. Note that if the
value is ``CDATA'', it will <EM>not</EM> have escape sequences for 8-bit
characters, record ends, or SDATA processed -- that will be your
responsibility.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_is_implied"><CODE>is_implied()</CODE>: Return <CODE>true</CODE> (ie. 1) if the value of the
attribute is implied, or <CODE>false</CODE> (ie. 0) if it is specified in the
document.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_set_type"><CODE>set_type(TYPE)</CODE>: Change the type of the attribute to the
string <CODE>TYPE</CODE> (which should be all in upper case). Available types
are ``IMPLIED'', ``CDATA'', ``NOTATION'', ``ENTITY'', and ``TOKEN''.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_set_value"><CODE>set_value(VALUE)</CODE>: Change the value of the attribute to
<CODE>VALUE</CODE>, which may be a string, an <CODE>SGMLS_Entity</CODE> object, or an
<CODE>SGMLS_Notation</CODE> subject, depending on the attribute's type.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>ext()</CODE>: Return a reference to an associative array available
for user-defined extensions.</STRONG><BR>
<DD>
</DL>
<P>
<H2><A NAME="the sgmls_notation class">The <CODE>SGMLS_Notation</CODE> class</A></H2>
<P>All declared notations appear as objects belonging to this class,
which recognises the following methods:</P>
<DL>
<DT><STRONG><CODE>name()</CODE>: Return a string containing the name of the notation.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_sysid"><CODE>sysid()</CODE>: Return a string containing the system identifier of
the notation, if any.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_pubid"><CODE>pubid()</CODE>: Return a string containing the public identifier of
the notation, if any.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>ext()</CODE>: Return a reference to an associative array available
for user-defined extensions.</STRONG><BR>
<DD>
</DL>
<P>
<H2><A NAME="the sgmls_entity class">The <CODE>SGMLS_Entity</CODE> class</A></H2>
<P>All declared entities appear as objects belonging to this class, which
recognises the following methods:</P>
<DL>
<DT><STRONG><CODE>name()</CODE>: Return a string containing the name of the entity, in
mixed case.</STRONG><BR>
<DD>
<DT><STRONG><CODE>type()</CODE>: Return a string containing the type of the entity, in
upper case. Available types are ``CDATA'', ``SDATA'', ``NDATA'' (external
entities only), ``SUBDOC'', ``PI'' (newer versions of <STRONG>nsgmls</STRONG> only), or
``TEXT'' (newer versions of <STRONG>nsgmls</STRONG> only).</STRONG><BR>
<DD>
<DT><STRONG><CODE>value()</CODE>: Return a string containing the value of the entity,
if it is internal.</STRONG><BR>
<DD>
<DT><STRONG><CODE>sysid()</CODE>: Return a string containing the system identifier of
the entity (if any), if it is external.</STRONG><BR>
<DD>
<DT><STRONG><CODE>pubid()</CODE>: Return a string containing the public identifier of
the entity (if any), if it is external.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_filenames"><CODE>filenames()</CODE>: Return an array of strings containing any file
names generated from the identifiers, if the entity is external.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>notation()</CODE>: Return the <CODE>SGMLS_Notation</CODE> object associated
with the entity, if it is external.</STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_data_attributes"><CODE>data_attributes()</CODE>: Return a reference to an associative array
of data attribute names (in upper case) and the associated
<CODE>SGMLS_Attribute</CODE> objects for the current entity.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_data_attribute_names"><CODE>data_attribute_names()</CODE>: Return an array of data attribute
names (in upper case) for the current entity.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_data_attribute"><CODE>data_attribute(ANAME)</CODE>: Return the <CODE>SGMLS_Attribute</CODE> object
for the data attribute named <CODE>ANAME</CODE> for the current entity.</A></STRONG><BR>
<DD>
<DT><STRONG><A NAME="item_set_data_attribute"><CODE>set_data_attribute(ATTRIB)</CODE>: Add the <CODE>SGMLS_Attribute</CODE> object
<CODE>ATTRIB</CODE> to the current entity, replacing any other data attribute
with the same name.</A></STRONG><BR>
<DD>
<DT><STRONG><CODE>ext()</CODE>: Return a reference to an associative array for
user-defined extensions.</STRONG><BR>
<DD>
</DL>
<P>
<HR>
<H1><A NAME="author and copyright">AUTHOR AND COPYRIGHT</A></H1>
<P>Copyright 1994 and 1995 by David Megginson,
<CODE>dmeggins@aix1.uottawa.ca</CODE>. Distributed under the terms of the Gnu
General Public License (version 2, 1991) -- see the file <CODE>COPYING</CODE>
which is included in the <STRONG>SGMLS.pm</STRONG> distribution.</P>
<P>
<HR>
<H1><A NAME="see also:">SEE ALSO:</A></H1>
<P><A HREF="../../site/lib/SGMLS/Output.html">the SGMLS::Output manpage</A> and <A HREF="../../site/lib/SGMLS/Refs.html">the SGMLS::Refs manpage</A>.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> SGMLS - class for postprocessing the output from the B<sgmls> and
B<nsgmls> parsers.</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>