home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / doc / libxml-perl / UsingPatActModules.pod < prev    next >
Encoding:
Text File  |  1999-08-10  |  3.2 KB  |  76 lines

  1. =head1 Using PatAct Modules
  2.  
  3. This document is targeted towards people who want to write scripts or
  4. modules that use pattern and action modules.  If you want to create a
  5. new pattern or action module, please see ``Creating PatAct Modules.''
  6.  
  7. You would want to use pattern/action modules if you want to apply a
  8. complex set of patterns or queries against an XML instance and perform
  9. actions associated with those patterns or queries.  To be able to use
  10. pattern/action modules you will need a pattern-matching module that
  11. supports the format of the pattern or query language you can use and
  12. an action module that will perform the types of actions you need to
  13. perform.
  14.  
  15. Available pattern-matching modules are:
  16.  
  17.   XML::PatAct::
  18.   ::MatchName    Simple element name, element hierarchy matching
  19.  
  20. Available action modules are:
  21.  
  22.   XML::PatAct::
  23.   ::ToObjects    Convert XML instances into Perl objects
  24.   ::Amsterdam    Simplistic style-sheet using before/after strings
  25.  
  26. Using pattern/action modules involves loading the modules, creating a
  27. pattern/action list, creating instances of the pattern and matching
  28. modules, and then starting a parse using the matching module as a
  29. handler:
  30.  
  31.   use XML::Parser::PerlSAX;
  32.   use XML::PatAct::MatchName;
  33.   use XML::PatAct::ToObjects;
  34.  
  35.   my $patterns = [
  36.       'schema'      => [ qw{ -holder                    } ],
  37.       'table'       => [ qw{ -make Schema::Table        } ],
  38.       'name'        => [ qw{ -field Name -as-string     } ],
  39.   ];
  40.  
  41.   my $matcher = XML::PatAct::MatchName->new( Patterns => $patterns );
  42.   my $handler = XML::PatAct::ToObjects->new( Patterns => $patterns,
  43.                                              Matcher => $matcher);
  44.  
  45.   my $parser = XML::Parser::PerlSAX->new( Handler => $handler );
  46.   my $schema = $parser->parse(Source => { SystemId => $ARGV[0] } );
  47.  
  48. The example above use the MatchName and ToObjects pattern and action
  49. modules.  The pattern list contains pairs of patterns and actions in
  50. the format specified by MatchName and ToObjects, other modules will
  51. use other formats.  The patterns that MatchName supports are a simple
  52. element name or a hierarchy of element names.  The actions that
  53. ToObjects support describe how to create Perl objects from the XML
  54. instances.
  55.  
  56. The $matcher object is an instance of XML::PatAct::MatchName.
  57. $matcher is created and associated with the pattern/action list that
  58. will be matched against.  The $handler object is an instance of
  59. XML::PatAct::ToObjects.  $handler is created and associated with the
  60. pattern/action list to be matched against as well as the pattern
  61. matching instance $matcher.
  62.  
  63. $handler is a PerlSAX event handler.  XML::Parser::PerlSAX is used as
  64. the source of XML events.  Other PerlSAX event generators include
  65. XML::Grove::PerlSAX and XML::ESISParser.  $parser is created with the
  66. $handler object as it's Handler.
  67.  
  68. The `parse()' method of $parser is called to run the handler (the
  69. matching object) to produce the output from XML::PatAct::ToObjects,
  70. which is a Perl object converted from XML, $schema.
  71.  
  72. The above example is an abbrieviated version.  A complete example of
  73. usage of the MatchName and ToObjects modules, including source XML, is
  74. in the documentation for the XML::PatAct::ToObjects module.  The
  75. script and source XML are also in the examples directory.
  76.