Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Programming Guide

Example

The following example illustrates the use of the PLISAXA built-in subroutine and uses the example XML document cited above:

Figure 89. PLISAXA coding example - type declarations
  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_end_of_document
        limited entry( pointer )
        returns( byvalue fixed bin(31) )
        options( byvalue linkage(optlink) );

    define alias event_predefined_ref
        limited entry( pointer, char(1) )
        returns( byvalue fixed bin(31) )
        options( byvalue linkage(optlink) nodescriptor );

    define alias event_character_ref
        limited entry( pointer, fixed bin(31) )
        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_exception
        limited entry( pointer, pointer, fixed bin(31),
                       fixed bin(31) )
        returns( byvalue fixed bin(31) )
        options( byvalue linkage(optlink) );

Figure 90. PLISAXA coding example - event structure
  saxtest: proc options( main );

    dcl
      1 eventHandler static

        ,2 e01 type event
               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_end_of_document
               init( end_of_document )
        ,2 e07 type event
               init( start_of_element )
        ,2 e08 type event
               init( attribute_name )
        ,2 e09 type event
               init( attribute_characters )
        ,2 e10 type event_predefined_ref
               init( attribute_predefined_reference )
        ,2 e11 type event_character_ref
               init( attribute_character_reference )
        ,2 e12 type event
               init( end_of_element )
        ,2 e13 type event
               init( start_of_CDATA )
        ,2 e14 type event
               init( end_of_CDATA )
        ,2 e15 type event
               init( content_characters )
        ,2 e16 type event_predefined_ref
               init( content_predefined_reference )
        ,2 e17 type event_character_ref
               init( content_character_reference )
        ,2 e18 type event_pi
               init( processing_instruction )
        ,2 e19 type event
               init( comment )
        ,2 e20 type event
               init( unknown_attribute_reference )
        ,2 e21 type event
               init( unknown_content_reference )
        ,2 e22 type event
               init( start_of_prefix_mapping )
        ,2 e23 type event
               init( end_of_prefix_mapping )
        ,2 e24 type event_exception
               init( exception )
        ;

Figure 91. PLISAXA coding example - main routine
    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&quot;s best"/>'
    || '<?spread please use real mayonnaise ?>'
    || '<meat>Ham &amp; turkey</meat>'
    || '<filling>Cheese, lettuce, tomato, etc.</filling>'
    || '<![CDATA[We should add a <relish> element in future!]]>'.
    || '</sandwich>'
    || 'junk';


    call plisaxa( eventHandler,
                  addr(token),
                  addrdata(xmlDocument),
                  length(xmlDocument) );

  end;

Figure 92. PLISAXA coding example - event routines
  dcl chars char(32000) based;

  start_of_document:
    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() )
     || ' 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;

  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 )
    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;

  attribute_name:
    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;

  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;
  attribute_predefined_reference:
    proc( userToken, reference )
    returns( byvalue fixed bin(31) )
    options( byvalue linkage(optlink) nodescriptor );

    dcl userToken      pointer;
    dcl reference   char(1);

    put skip list( lowercase( procname() )
     || ' ' || hex(reference ) );

    return(0);
  end;

  attribute_character_reference:
    proc( userToken, reference )
    returns( byvalue fixed bin(31) )
    options( byvalue linkage(optlink) );

    dcl userToken      pointer;
    dcl reference      fixed bin(31);

    put skip list( lowercase( procname() )
     || ' <' || hex(reference ) );

    return(0);
  end;

  end_of_element:
    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, 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;

  end_of_CDATA:
    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;

  content_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;
  content_predefined_reference:
    proc( userToken, reference )
    returns( byvalue fixed bin(31) )
    options( byvalue linkage(optlink) nodescriptor );

    dcl userToken      pointer;
    dcl reference   char(1);

    put skip list( lowercase( procname() )
     || ' ' || hex(reference ) );

    return(0);
  end;

  content_character_reference:
    proc( userToken, reference )
    returns( byvalue fixed bin(31) )
    options( byvalue linkage(optlink) );

    dcl userToken      pointer;
    dcl reference      fixed bin(31);

    put skip list( lowercase( procname() )
     || ' <' || hex(reference ) );

    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;

  unknown_attribute_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;

  unknown_content_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;
  start_of_prefix_mapping:
    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;

  end_of_prefix_mapping:
    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;

The preceding program would produce the following output:

Figure 93. PLISAXA coding example - program output
  start_of_dcoument length=           305
  version_information <1.0>
  standalone_declaration <yes>
  comment <This document is just an example>
  start_of_element <sandwich>
  start_of_element <bread>
  attribute_name <type>
  attribute_characters <baker>
  attribute_predefined_reference 7D
  attribute_characters <s best>
  end_of_element <bread>
  processing_instruction <spread>
  start_of_element <meat>
  content_characters <Ham >
  content_predefined_reference 50
  content_characters < turkey>
  end_of_element <meat>
  start_of_element <filling>
  content_characters <Cheese, lettuce, tomato, etc.>
  end_of_element <filling>
  start_of_cdata <<![CDATA[>
  content_characters <We should add a <relish> element in future!>
  end_of_cdata <]]>
  end_of_element <sandwich>
  exception errorid =             1
  content_characters <j>
  exception errorid =             1
  content_characters <u>
  exception errorid =             1
  content_characters <n>
  exception errorid =             1
  content_characters <k>
  end_of_document

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)