The following example illustrates the use of the PLISAXC built-in subroutine and uses the example XML document cited above. This example is essentially the same as that used in the previous chapter: it doesn't use namespaces, and all the input is passed when PLISAXC is first invoked (and as a result, the end_of_input event should not be invoked). But this makes it easy to contrast the behavior of these 2 parsers.
saxtest: package exports(saxtest);
define alias event
limited entry( pointer, pointer, fixed bin(31) )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_with_flag
limited entry( pointer, pointer, fixed bin(31),
bit(8) aligned )
returns( byvalue fixed bin(31) )
options( nodescriptor byvalue linkage(optlink) );
define alias event_with_namespace
limited entry( pointer, pointer, fixed bin(31),
pointer, fixed bin(31),
pointer, fixed bin(31) )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_without_data
limited entry( pointer )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_pi
limited entry( pointer, pointer, fixed bin(31),
pointer, fixed bin(31) )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_namespace_dcl
limited entry( pointer, pointer, fixed bin(31),
pointer, fixed bin(31) )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_exception
limited entry( pointer, fixed bin(31),
fixed bin(31),
fixed bin(31) )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
define alias event_end_of_input
limited entry( pointer,
pointer byaddr,
fixed bin(31) byaddr )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
saxtest: proc options( main );
dcl
1 eventHandler static
,2 e01 type event_without_data
init( start_of_document )
,2 e02 type event
init( version_information )
,2 e03 type event
init( encoding_declaration )
,2 e04 type event
init( standalone_declaration )
,2 e05 type event
init( document_type_declaration )
,2 e06 type event_without_data
init( end_of_document )
,2 e07 type event_with_namespace
init( start_of_element )
,2 e08 type event_with_namespace
init( attribute_name )
,2 e09 type event
init( attribute_characters )
,2 e10 type event_with_namespace
init( end_of_element )
,2 e11 type event_without_data
init( start_of_CDATA )
,2 e12 type event_without_data
init( end_of_CDATA )
,2 e13 type event_with_flag
init( content_characters )
,2 e14 type event_pi
init( processing_instruction )
,2 e15 type event
init( comment )
,2 e16 type event_namespace_dcl
init( namespace_declare )
,2 e17 type event_end_of_input
init( end_of_input )
,2 e18 type event
init( unresolved_reference )
,2 e19 type event_exception
init( exception )
;
dcl token char(8);
dcl xmlDocument char(4000) var;
xmlDocument =
'<?xml version="1.0" standalone="yes"?>'
|| '<!--This document is just an example-->'
|| '<sandwich>'
|| '<bread type="baker’s best"/>'
|| '<?spread please use real mayonnaise ?>'
|| '<meat>Ham & turkey</meat>'
|| '<filling>Cheese, lettuce, tomato, etc.</filling>'
|| '<![CDATA[We should add a <relish> element in future!]]>'.
|| '</sandwich>'
|| ' ';
call plisaxc( eventHandler,
addr(token),
addrdata(xmlDocument),
length(xmlDocument) );
end;
dcl chars char(32000) based;
start_of_document:
proc( userToken )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' length=' || tokenlength );
return(0);
end;
version_information:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
encoding_declaration:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
standalone_declaration:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
document_type_declaration:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
namespace_declare:
proc( userToken, nsPrefix, nsPrefixLength,
nsUri, nsUriLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl nsPrefix pointer;
dcl nsPrefixLength fixed bin(31);
dcl nsUri pointer;
dcl nsUriLength fixed bin(31);
put skip list( lowercase( procname() ) );
put skip list( 'prefix = '
|| ' <' || substr(nsPrefix->chars,1,nsPrefixlength ) || '>' );
put skip list( 'Uri = '
|| ' <' || substr(nsUri->chars,1,nsUrilength ) || '>' );
return(0);
end;
end_of_document:
proc( userToken )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
put skip list( lowercase( procname() ) );
return(0);
end;
start_of_element:
proc( userToken, xmlToken, TokenLength,
nsPrefix, nsPrefixLength,
nsUri, nsUriLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
dcl nsPrefix pointer;
dcl nsPrefixLength fixed bin(31);
dcl nsUri pointer;
dcl nsUriLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
attribute_name:
proc( userToken, xmlToken, TokenLength,
nsPrefix, nsPrefixLength,
nsUri, nsUriLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
dcl nsPrefix pointer;
dcl nsPrefixLength fixed bin(31);
dcl nsUri pointer;
dcl nsUriLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
end_of_element:
proc( userToken, xmlToken, TokenLength,
nsPrefix, nsPrefixLength,
nsUri, nsUriLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
dcl nsPrefix pointer;
dcl nsPrefixLength fixed bin(31);
dcl nsUri pointer;
dcl nsUriLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
content_characters:
proc( userToken, xmlToken, TokenLength, flags )
returns( byvalue fixed bin(31) )
options( nodescriptor, byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
dcl flags bit(8) aligned;
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
if flags = ''b then;
else
put skip list( '!!flags = ' || flags );
return(0);
end;
attribute_characters:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
start_of_CDATA:
proc( userToken )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
put skip list( lowercase( procname() ) );
return(0);
end;
end_of_CDATA:
proc( userToken )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
put skip list( lowercase( procname() ) );
return(0);
end;
processing_instruction:
proc( userToken,
piTarget, piTargetLength,
piData, piDataLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl piTarget pointer;
dcl piTargetLength fixed bin(31);
dcl piData pointer;
dcl piDataLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(piTarget->chars,1,piTargetLength ) || '>' );
return(0);
end;
comment:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
unresolved_reference:
proc( userToken, xmlToken, TokenLength )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl tokenLength fixed bin(31);
put skip list( lowercase( procname() )
|| ' <' || substr(xmltoken->chars,1,tokenlength ) || '>' );
return(0);
end;
exception:
proc( userToken, xmlToken, currentOffset, errorID )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl xmlToken pointer;
dcl currentOffset fixed bin(31);
dcl errorID fixed bin(31);
put skip list( lowercase( procname() )
|| ' errorid =' || errorid );
return(0);
end;
end_of_input:
proc( userToken, addr_xml, length_xml )
returns( byvalue fixed bin(31) )
options( byvalue linkage(optlink) );
dcl userToken pointer;
dcl addr_xml byaddr pointer;
dcl length_xml byaddr fixed bin(31);
return(1);
end;
end;The preceding program would produce the following output:
start_of_document version_information <1.0> standalone_declaration <yes> comment <This document is just an example> start_of_element <sandwich> prefix = <> Uri = <> start_of_element <bread> prefix = <> Uri = <> attribute_name <type> prefix = <> Uri = <> attribute_characters <baker’s best> end_of_element <bread> prefix = <> Uri = <> processing_instruction <spread> piData = <please use real mayonnaise > start_of_element <meat> prefix = <> Uri = <> content_characters <Ham & turkey> end_of_element <meat> prefix = <> Uri = <> start_of_element <filling> prefix = <> Uri = <> content_characters <Cheese, lettuce, tomato, etc.> !!flags = 01000000 end_of_element <filling> prefix = <> Uri = <> start_of_cdata content_characters <We should add a <relish> element in future > end_of_cdata end_of_element <sandwich> prefix = <> Uri = <> end_of_document