libxml-grove-perl-0.46alpha.orig/0042775000175000017500000000000007004335700015421 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/lib/0042775000175000017500000000000007004335700016167 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/lib/XML/0042775000175000017500000000000007004335700016627 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/lib/XML/Grove.pm0100664000175000017500000002674007004334705020257 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # XML::Grove is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: Grove.pm,v 1.15 1999/08/17 15:01:28 kmacleod Exp $ # use strict; use 5.005; use UNIVERSAL; use Data::Grove; package XML::Grove; use vars qw{$VERSION @ISA}; $VERSION = '0.46alpha'; @ISA = qw{Data::Grove}; package XML::Grove::Document; use vars qw{@ISA $type_name}; @ISA = qw{XML::Grove}; $type_name = 'document'; # Override methods that may be loaded from Data::Grove::Parent. In # XML::Grove, `root' and `rootpath' refer to the root _element_ of the # grove, not the document that contains it. # Note: this routine specifically sets $value and does last instead of # returning $child immediately because there is a bug in Perl 5.005 that # causes the returned value to disappear sub root { my $self = shift; if (@_) { return $self->{Contents} = [ shift ]; } else { my $value = undef; foreach my $child (@{$self->{Contents}}) { if ($child->isa('XML::Grove::Element')) { $value = $child; last; } } return $value; } } sub rootpath { return; } package XML::Grove::Element; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'element'; package XML::Grove::PI; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'pi'; package XML::Grove::Entity::External; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'external_entity'; package XML::Grove::Entity::SubDoc; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'subdoc_entity'; package XML::Grove::Entity::SGML; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'sgml_entity'; package XML::Grove::Entity; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'entity'; package XML::Grove::Notation; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'notation'; package XML::Grove::Comment; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'comment'; package XML::Grove::SubDoc; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'subdoc'; package XML::Grove::Characters; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'characters'; package XML::Grove::CData; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'cdata'; package XML::Grove::ElementDecl; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'element_decl'; package XML::Grove::AttListDecl; use vars qw{ @ISA $type_name }; @ISA = qw{XML::Grove}; $type_name = 'attlist_decl'; 1; __END__ =head1 NAME XML::Grove - Perl-style XML objects =head1 SYNOPSIS use XML::Grove; # Basic parsing and grove building use XML::Grove::Builder; use XML::Parser::PerlSAX; $grove_builder = XML::Grove::Builder->new; $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder ); $document = $parser->parse ( Source => { SystemId => 'filename' } ); # Creating new objects $document = XML::Grove::Document->new ( Contents => [ ] ); $element = XML::Grove::Element->new ( Name => 'tag', Attributes => { }, Contents => [ ] ); # Accessing XML objects $tag_name = $element->{Name}; $contents = $element->{Contents}; $parent = $element->{Parent}; $characters->{Data} = 'XML is fun!'; =head1 DESCRIPTION XML::Grove is a tree-based object model for accessing the information set of parsed or stored XML, HTML, or SGML instances. XML::Grove objects are Perl hashes and arrays where you access the properties of the objects using normal Perl syntax: $text = $characters->{Data}; =head2 How To Create a Grove There are several ways for groves to come into being, they can be read from a file or string using a parser and a grove builder, they can be created by your Perl code using the `C' methods of XML::Grove::Objects, or databases or other sources can act as groves. The most common way to build groves is using a parser and a grove builder. The parser is the package that reads the characters of an XML file, recognizes the XML syntax, and produces ``events'' reporting when elements (tags), text (characters), processing instructions, and other sequences occur. A grove builder receives (``consumes'' or ``handles'') these events and builds XML::Grove objects. The last thing the parser does is return the XML::Grove::Document object that the grove builder created, with all of it's elements and character data. The most common parser and grove builder are XML::Parser::PerlSAX (in libxml-perl) and XML::Grove::Builder. To build a grove, create the grove builder first: $grove_builder = XML::Grove::Builder->new; Then create the parser, passing it the grove builder as it's handler: $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder ); This associates the grove builder with the parser so that every time you parse a document with this parser it will return an XML::Grove::Document object. To parse a file, use the `C' parameter to the `C' method containing a `C' parameter (URL or path) of the file you want to parse: $document = $parser->parse ( Source => { SystemId => 'kjv.xml' } ); To parse a string held in a Perl variable, use the `C' parameter containing a `C' parameter: $document = $parser->parse ( Source => { String => $xml_text } ); The following are all parsers that work with XML::Grove::Builder: XML::Parser::PerlSAX (in libxml-perl, uses XML::Parser) XML::ESISParser (in libxml-perl, uses James Clark's `nsgmls') XML::SAX2Perl (in libxml-perl, translates SAX 1.0 to PerlSAX) Most parsers supply more properties than the standard information set below and XML::Grove will make available all the properties given by the parser, refer to the parser documentation to find out what additional properties it may provide. Although there are not any available yet (August 1999), PerlSAX filters can be used to process the output of a parser before it is passed to XML::Grove::Builder. XML::Grove::PerlSAX can be used to provide input to PerlSAX filters or other PerlSAX handlers. =head2 Using Groves The properties provided by parsers are available directly using Perl's normal syntax for accessing hashes and arrays. For example, to get the name of an element: $element_name = $element->{Name}; By convention, all properties provided by parsers are in mixed case. `C' properties are available using the `C' module. The following is the minimal set of objects and their properties that you are likely to get from all parsers: =head2 XML::Grove::Document The Document object is parent of the root element of the parsed XML document. =over 12 =item Contents An array containing the root element. =back A document's `Contents' may also contain processing instructions, comments, and whitespace. Some parsers provide information about the document type, the XML declaration, or notations and entities. Check the parser documentation for property names. =head2 XML::Grove::Element The Element object represents elements from the XML source. =over 12 =item Parent The parent object of this element. =item Name A string, the element type name of this element =item Attributes A hash of strings or arrays =item Contents An array of elements, characters, processing instructions, etc. =back In a purely minimal grove, the attributes of an element will be plain text (Perl scalars). Some parsers provide access to notations and entities in attributes, in which case the attribute may contain an array. =head2 XML::Grove::Characters The Characters object represents text from the XML source. =over 12 =item Parent The parent object of this characters object =item Data A string, the characters =back =head2 XML::Grove::PI The PI object represents processing instructions from the XML source. =over 12 =item Parent The parent object of this PI object. =item Target A string, the processing instruction target. =item Data A string, the processing instruction data, or undef if none was supplied. =back In addition to the minimal set of objects above, XML::Grove knows about and parsers may provide the following objects. Refer to the parser documentation for descriptions of the properties of these objects. XML::Grove:: ::Entity::External External entity reference ::Entity::SubDoc External SubDoc reference (SGML) ::Entity::SGML External SGML reference (SGML) ::Entity Entity reference ::Notation Notation declaration ::Comment ::SubDoc A parsed subdocument (SGML) ::CData A CDATA marked section ::ElementDecl An element declaration from the DTD ::AttListDecl An element's attribute declaration, from the DTD =head1 METHODS XML::Grove by itself only provides one method, new(), for creating new XML::Grove objects. There are Data::Grove and XML::Grove extension modules that give additional methods for working with XML::Grove objects and new extensions can be created as needed. =over 4 =item $obj = XML::Grove::OBJECT->new( [PROPERTIES] ) `C' creates a new XML::Grove object with the type I, and with the initial I. I may be given as either a list of key-value pairs, a hash, or an XML::Grove object to copy. I may be any of the objects listed above. =back This is a list of available extensions and the methods they provide (as of Feb 1999). Refer to their module documentation for more information on how to use them. XML::Grove::AsString as_string return portions of groves as a string attr_as_string return an element's attribute as a string XML::Grove::AsCanonXML as_canon_xml return XML text in canonical XML format XML::Grove::PerlSAX parse emulate a PerlSAX parser using the grove objects Data::Grove::Parent root return the root element of a grove rootpath return an array of all objects between the root element and this object, inclusive Data::Grove::Parent also adds `C' and `C' properties to grove objects. Data::Grove::Visitor accept call back a subroutine using an object type name accept_name call back using an element or tag name children_accept for each child in Contents, call back a sub children_accept_name same, but using tag names attr_accept call back for the objects in attributes XML::Grove::IDs get_ids return a list of all ID attributes in grove XML::Grove::Path at_path $el->at_path('/html/body/ul/li[4]') XML::Grove::Sub filter run a sub against all the objects in the grove =head1 WRITING EXTENSIONS The class `C' is the superclass of all classes in the XML::Grove module. `C' is a subclass of `C'. If you create an extension and you want to add a method to I XML::Grove objects, then create that method in the XML::Grove package. Many extensions only need to add methods to XML::Grove::Document and/or XML::Grove::Element. When you create an extension you should definitly provide a way to invoke your module using objects from your package too. For example, XML::Grove::AsString's `C' method can also be called using an XML::Grove::AsString object: $writer= new XML::Grove::AsString; $string = $writer->as_string ( $xml_object ); =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/0042775000175000017500000000000007004335700017711 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/lib/XML/Grove/AsCanonXML.pm0100664000175000017500000000727507004334705022164 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::AsCanonXML is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: AsCanonXML.pm,v 1.6 1999/08/17 18:36:20 kmacleod Exp $ # use strict; package XML::Grove::AsCanonXML; use vars qw{%char_entities}; use Data::Grove::Visitor; %char_entities = ( "\x09" => ' ', "\x0a" => ' ', "\x0d" => ' ', '&' => '&', '<' => '<', '>' => '>', '"' => '"', ); sub new { my $class = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; return bless $self, $class; } sub as_canon_xml { my $self = shift; my $object = shift; my $fh = shift; if (defined $fh) { return (); } else { return join('', $object->accept($self, $fh)); } } sub visit_document { my $self = shift; my $document = shift; return $document->children_accept($self, @_); } sub visit_element { my $self = shift; my $element = shift; my $fh = shift; my @return; push @return, $self->_print($fh, '<' . $element->{Name}); my $key; my $attrs = $element->{Attributes}; foreach $key (sort keys %$attrs) { push @return, $self->_print($fh, " $key=\"" . $self->_escape($attrs->{$key}) . '"'); } push @return, $self->_print($fh, '>'); push @return, $element->children_accept($self, $fh, @_); push @return, $self->_print($fh, '{Name} . '>'); return @return; } sub visit_entity { # entities don't occur in text return (); } sub visit_pi { my $self = shift; my $pi = shift; my $fh = shift; return $self->_print($fh, '{Target} . ' ' . $pi->{Data} . '?>'); } sub visit_comment { my $self = shift; my $comment = shift; my $fh = shift; if ($self->{Comments}) { return $self->_print($fh, ''); } else { return (); } } sub visit_characters { my $self = shift; my $characters = shift; my $fh = shift; return ($self->_print($fh, $self->_escape($characters->{Data}))); } sub _print { my $self = shift; my $fh = shift; my $string = shift; if (defined $fh) { $fh->print($string); return (); } else { return ($string); } } sub _escape { my $self = shift; my $string = shift; $string =~ s/([\x09\x0a\x0d&<>"])/$char_entities{$1}/ge; return $string; } package XML::Grove; sub as_canon_xml { my $xml_object = shift; return XML::Grove::AsCanonXML->new(@_)->as_canon_xml($xml_object); } 1; __END__ =head1 NAME XML::Grove::AsCanonXML - output XML objects in canonical XML =head1 SYNOPSIS use XML::Grove::AsCanonXML; # Using as_canon_xml method on XML::Grove objects: $string = $xml_object->as_canon_xml( OPTIONS ); # Using an XML::Grove::AsCanonXML instance: $writer = XML::Grove::AsCanonXML->new( OPTIONS ); $string = $writer->as_canon_xml($xml_object); $writer->as_canon_xml($xml_object, $file_handle); =head1 DESCRIPTION C will return a string or write a stream of canonical XML for an XML object and it's content (if any). C objects hold the options used for writing the XML objects. Options can be supplied when the the object is created, $writer = XML::Grove::AsCanonXML->new( Comments => 1 ); or modified at any time before writing an XML object by setting the option directly in the `C<$writer>' hash. =head1 OPTIONS =over 4 =item Comments By default comments are not written to the output. Setting comment to TRUE will include comments in the output. =back =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Parser(3), XML::Grove(3). James Clark's Canonical XML definition =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/AsString.pm0100664000175000017500000001156507004334705022010 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::AsString is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: AsString.pm,v 1.6 1999/08/25 17:08:09 kmacleod Exp $ # use strict; package XML::Grove::AsString; use Data::Grove::Visitor; sub new { my $class = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; return bless $self, $class; } sub as_string { my $self = shift; my $object = shift; my $fh = shift; if (defined $fh) { return (); } else { return join('', $object->accept($self, $fh)); } } sub visit_document { my $self = shift; my $document = shift; return $document->children_accept($self, @_); } sub visit_element { my $self = shift; my $element = shift; return $element->children_accept($self, @_); } sub visit_entity { my $self = shift; my $entity = shift; my $fh = shift; my $mapper = $self->{EntityMap}; return '' if (!defined $mapper); my $mapping; if (ref($mapper) eq 'CODE') { $mapping = &$mapper($entity->{Data}, $self->{EntityMapOptions}); } else { $mapping = $mapper->lookup($entity->{Data}, $self->{EntityMapOptions}); } if ($self->{EntityMapFilter}) { my $filter = $self->{Filter}; if (defined $filter) { $mapping = &$filter($mapping); } } return $self->_print($fh, $mapping); } sub visit_pi { return (); } sub visit_comment { return (); } sub visit_characters { my $self = shift; my $characters = shift; my $fh = shift; my $data = $characters->{Data}; if (defined ($self->{Filter})) { $data = &{$self->{Filter}}($data); } return $self->_print($fh, $data); } sub _print { my $self = shift; my $fh = shift; my $string = shift; if (defined $fh) { $fh->print($string); return (); } else { return ($string); } } package XML::Grove; sub as_string { my $xml_object = shift; return XML::Grove::AsString->new(@_)->as_string($xml_object); } package XML::Grove::Element; sub attr_as_string { my $element = shift; my $attr = shift; my $writer = new XML::Grove::AsString (@_); return $element->attr_accept ($attr, $writer); } 1; __END__ =head1 NAME XML::Grove::AsString - output content of XML objects as a string =head1 SYNOPSIS use XML::Grove::AsString; # Using as_string method on XML::Grove::Document or XML::Grove::Element: $string = $xml_object->as_string OPTIONS; $string = $element->attr_as_string $attr, OPTIONS; # Using an XML::Grove::AsString instance: $writer = new XML::Grove::AsString OPTIONS; $string = $writer->as_string($xml_object); $writer->as_string($xml_object, $file_handle); =head1 DESCRIPTION Calling `C' on an XML object returns the character data contents of that object as a string, including all elements below that object. Calling `C' on an element returns the contents of the named attribute as a string. Comments, processing instructions, and, by default, entities all return an empty string. I may either be a key-value list or a hash containing the options described below. I may be modified directly in the object. The default options are no filtering and entities are mapped to empty strings. =head1 OPTIONS =over 4 =item Filter `C' is an anonymous sub that gets called to process character data before it is appended to the string to be returned. This can be used, for example, to escape characters that are special in output formats. The `C' sub is called like this: $string = &$filter ($character_data); =item EntityMap `C' is an object that accepts `C' methods or an anonymous sub that gets called with the entity replacement text (data) and mapper options as arguments and returns the corresponding character replacements. It is called like this if it is an object: $replacement_text = $entity_map->lookup ($entity_data, $entity_map_options); or this if it is a sub: $replacement_text = &$entity_map ($entity_data, $entity_map_options); =item EntityMapOptions `C' is a hash passed through to the `C' method or anonymous sub, the type of value is defined by the entity mapping package or the anonymous sub. =item EntityMapFilter `C' is a flag to indicate if mapped entities should be filtered after mapping. =back =head1 EXAMPLES Here is an example of entity mapping using the Text::EntityMap module: use Text::EntityMap; use XML::Grove::AsString; $html_iso_dia = Text::EntityMap->load ('ISOdia.2html'); $html_iso_pub = Text::EntityMap->load ('ISOpub.2html'); $html_map = Text::EntityMap->group ($html_iso_dia, $html_iso_pub); $element->as_string (EntityMap => $html_map); =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/Builder.pm0100664000175000017500000001501507004334705021636 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::Builder is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # # $Id: Builder.pm,v 1.5 1999/08/17 15:01:28 kmacleod Exp $ # # # implements these handlers: # # PerlSAX defined handlers # # start_document -- beginning of a document # end_document -- end of a document # start_element -- beginning of an element # end_element -- end of an element # characters -- character data # ignorable_whitespace -- ignorable whitespace in element content # processing_instruction -- processing instruction (PI) # # Additional handlers # # record_end -- record_end # ext_entity -- external entity definition # subdoc_entity -- subdoc entity definition # ext_sgml_entity -- external SGML text entity definition # int_entity -- internal entity definition # ext_entity_ref -- external entityt reference # int_entity_ref -- internal entity reference # notation -- notation definition # comment -- comment # start_subdoc -- start of subdoc entity # end_subdoc -- end of subdoc entity # appinfo -- defined value of APPINFO # conforming -- document is conforming # error -- error use strict; package XML::Grove::Builder; use XML::Grove; sub new { my $type = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; return bless $self, $type; } sub start_document { my $self = shift; my $document = shift; $self->{lists} = []; $self->{cur_list} = []; $self->{Grove} = new XML::Grove::Document (%$document, Contents => $self->{cur_list}); } sub end_document { my $self = shift; my $grove = $self->{Grove}; delete $self->{cur_list}; delete $self->{lists}; delete $self->{Grove}; return $grove; } sub start_element { my $self = shift; my $properties = shift; my $contents = []; $properties->{Contents} = $contents; my $element = new XML::Grove::Element ($properties); push @{ $self->{lists} }, $self->{cur_list}; push @{ $self->{cur_list} }, $element; $self->{cur_list} = $contents; } sub end_element { my $self = shift; $self->{cur_list} = pop @{ $self->{lists} }; } sub characters { my $self = shift; push @{ $self->{cur_list} }, new XML::Grove::Characters (@_); } sub ignorable_whitespace { my $self = shift; push @{ $self->{cur_list} }, new XML::Grove::Characters (@_); } sub processing_instruction { my $self = shift; push @{ $self->{cur_list} }, new XML::Grove::PI (@_); } sub record_end { my $self = shift; push @{ $self->{cur_list} }, new XML::Grove::Characters (Data => "\n"); } sub external_entity_decl { my $self = shift; my $ext_entity = new XML::Grove::Entity::External (@_); my $notation = $ext_entity->{Notation}; if (defined($notation) && !ref($notation)) { $ext_entity->{Notation} = $self->{Grove}{Notations}{$notation}; } $self->{Grove}{Entities}{$ext_entity->{Name}} = $ext_entity; } sub subdoc_entity_decl { my $self = shift; my $ext_entity = new XML::Grove::Entity::SubDoc (@_); $self->{Grove}{Entities}{$ext_entity->{Name}} = $ext_entity; } sub external_sgml_entity_decl { my $self = shift; my $ext_entity = new XML::Grove::Entity::SGML (@_); $self->{Grove}{Entities}{$ext_entity->{Name}} = $ext_entity; } sub internal_entity_decl { my $self = shift; my $int_entity = new XML::Grove::Entity (@_); $self->{Grove}{Entities}{$int_entity->{Name}} = $int_entity; } sub external_entity_ref { my $self = shift; my $properties = shift; my $ext_entity = $self->{Grove}{Entities}{$properties->{Name}}; if (defined $ext_entity) { push @{ $self->{cur_list} }, $ext_entity; } elsif (!defined $self->{'warn_undefined_entity'}{$properties->{Name}}) { $self->{'warn_undefined_entity'}{$properties->{Name}} = 1; $self->error ({ Message => "XML::Grove::Builder: external entity \`$properties->{Name}' not defined" }); } } sub internal_entity_ref { my $self = shift; my $properties = shift; my $int_entity = $self->{Grove}{Entities}{$properties->{Name}}; if (defined $int_entity) { push @{ $self->{cur_list} }, $int_entity; } elsif (!defined $self->{'warn_undefined_entity'}{$properties->{Name}}) { $self->{'warn_undefined_entity'}{$properties->{Name}} = 1; $self->error ({ Message => "XML::Grove::Builder: internal entity \`$properties->{Name}' not defined" }); } } sub notation_decl { my $self = shift; my $notation = new XML::Grove::Notation (@_); $self->{Grove}{Notations}{$notation->{Name}} = $notation; } sub comment { my $self = shift; my $comment = new XML::Grove::Comment (@_); push @{ $self->{cur_list} }, $comment; } sub subdoc_start { my $self = shift; my $properties = shift; my $contents = []; $properties->{Contents} = $contents; my $subdoc = new XML::Grove::SubDoc ($properties); push @{ $self->{lists} }, $self->{cur_list}; push @{ $self->{cur_list} }, $subdoc; $self->{cur_list} = $contents; } sub subdoc_end { my $self = shift; $self->{cur_list} = pop @{ $self->{lists} }; } sub appinfo { my $self = shift; my $appinfo = shift; $self->{Grove}{AppInfo} = $appinfo->{AppInfo}; } sub conforming { my $self = shift; $self->{Grove}{Conforming} = 1; } sub warning { my $self = shift; my $error = shift; push (@{ $self->{Grove}{Errors} }, $error); } sub error { my $self = shift; my $error = shift; push (@{ $self->{Grove}{Errors} }, $error); } sub fatal_error { my $self = shift; my $error = shift; push (@{ $self->{Grove}{Errors} }, $error); } 1; __END__ =head1 NAME XML::Grove::Builder - PerlSAX handler for building an XML::Grove =head1 SYNOPSIS use PerlSAXParser; use XML::Grove::Builder; $builder = XML::Grove::Builder->new(); $parser = PerlSAXParser->new( Handler => $builder ); $grove = $parser->parse( Source => [SOURCE] ); =head1 DESCRIPTION C is a PerlSAX handler for building an XML::Grove. C is used by creating a new instance of C and providing it as the Handler for a PerlSAX parser. Calling `C' on the PerlSAX parser will return the grove built from that parse. =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3), PerlSAX.pod Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/Factory.pm0100664000175000017500000002004307004334705021654 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::Factory is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: Factory.pm,v 1.1 1999/09/03 21:41:00 kmacleod Exp $ # use strict; package XML::Grove::Factory; sub grove_factory { my $type = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; bless $self, $type; return $self; } sub element_factory { my $type = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; bless $self, 'XML::Grove::Factory_'; return $self; } sub element_functions { my $type = shift; my $prefix = shift; my $package = caller; foreach my $name (@_) { my $eval_str = <<'EOF;'; package @PACKAGE@; sub @NAME@ { if (ref($_[0]) eq 'HASH') { my $attributes = { %{(shift)} }; return XML::Grove::Element->new( Name => '@NAME@', Attributes => $attributes, Contents => XML::Grove::Factory::chars_(@_) ); } else { return XML::Grove::Element->new( Name => '@NAME@', Contents => XML::Grove::Factory::chars_(@_) ); } } EOF; $eval_str =~ s'@PACKAGE@'$package'ge; $eval_str =~ s'@NAME@'$name'ge; eval $eval_str; die $@ if ($@); } } sub document { my $self = shift; return XML::Grove::Document->new( Contents => chars_(@_) ); } sub element { my $self = shift; my $name = shift; if (ref($_[0]) eq 'HASH') { my $attributes = { %{(shift)} }; return XML::Grove::Element->new( Name => $name, Attributes => $attributes, Contents => chars_(@_) ); } else { return XML::Grove::Element->new( Name => $name, Contents => chars_(@_) ); } } sub pi { my $self = shift; if ($#_ == 0) { my $data = shift; return XML::Grove::PI->new( Data => $data ); } else { my $target = shift; my $data = shift; return XML::Grove::PI->new( Target => $target, Data => $data ); } } sub comment { my $self = shift; my $comment = shift; return XML::Grove::Comment->new( Data => $comment ); } sub chars_ { my $chars = [ ]; foreach my $obj (@_) { if (ref $obj) { push @$chars, $obj; } else { push @$chars, XML::Grove::Characters->new( Data => $obj ); } } return $chars; } package XML::Grove::Factory_; use vars qw{ $AUTOLOAD }; sub AUTOLOAD { my $self = shift; my $name = $AUTOLOAD; $name =~ s/.*:://; return if $name eq 'DESTROY'; if (ref($_[0]) eq 'HASH') { my $attributes = { %{(shift)} }; return XML::Grove::Element->new( Name => $name, Attributes => $attributes, Contents => XML::Grove::Factory::chars_(@_) ); } else { return XML::Grove::Element->new( Name => $name, Contents => XML::Grove::Factory::chars_(@_) ); } } 1; __END__ =head1 NAME XML::Grove::Factory - simplify creation of XML::Grove objects =head1 SYNOPSIS use XML::Grove::Factory; ### An object that creates Grove objects directly my $gf = XML::Grove::Factory->grove_factory; $grove = $gf->document( CONTENTS ); $element = $gf->element( $name, { ATTRIBUTES }, CONTENTS ); $pi = $gf->pi( $target, $data ); $comment = $gf->comment( $data ); ### An object that creates elements by method name my $ef = XML::Grove::Factory->element_factory(); $element = $ef->NAME( { ATTRIBUTES }, CONTENTS); ### Similar to `element_factory', but creates functions in the ### current package XML::Grove::Factory->element_functions( PREFIX, ELEMENTS ); $element = NAME( { ATTRIBUTES }, CONTENTS ); =head1 DESCRIPTION C provides objects or defines functions that let you simply and quickly create the most commonly used XML::Grove objects. C supports three types of object creation. The first type is to create raw XML::Grove objects. The second type creates XML elements by element name. The third type is like the second, but defines local functions for you to call instead of using an object, which might save typing in some cases. The three types of factories can be mixed. For example, you can use local functions for all element names that don't conflict with your own sub names or contain special characters, and then use a `C' object for those elements that do conflict. In the examples that follow, each example is creating an XML instance similar to the following, assuming it's pretty printed: Some Title

A paragraph.

=head1 GROVE FACTORY =over 4 =item $gf = XML::Grove::Factory->grove_factory() Creates a new grove factory object that creates raw XML::Grove objects. =item $gf->document( I ); Creates an XML::Grove::Document object. I may contain processing instructions, strings containing only whitespace characters, and a single element object (but note that there is no checking). Strings are converted to XML::Grove::Characters objects. =item $gf->element($name, I); =item $gf->element($name, { I }, I); Creates an XML::Grove::Element object with the name `C<$name>'. If the argument following `C<$name>' is an anonymous hash, I, then they will be copied to the elements attributes. I will be stored in the element's content (note that there is no validity checking). Strings in I are converted to XML::Grove::Characters objects. =item $gf->pi( I, I) =item $gf->pi( I ) Create an XML::Grove::PI object with I and I. =item $gf->comment( I ) Create an XML::Grove::Comment object with I. =back =head2 GROVE FACTORY EXAMPLE use XML::Grove::Factory; $gf = XML::Grove::Factory->grove_factory; $element = $gf->element('HTML', $gf->element('HEAD', $gf->element('TITLE', 'Some Title')), $gf->element('BODY', { bgcolor => '#FFFFFF' }, $gf->element('P', 'A paragraph.'))); =head1 ELEMENT FACTORY =over 4 =item $ef = XML::Grove::Factory->element_factory() Creates a new element factory object for creating elements. `C' objects work by creating an element for any name used to call the object. =item $ef->I( I ) =item $ef->I( { I }, I) Creates an XML::Grove::Element object with the given I, I, and I. The hash containing I is optional if this element doesn't need attributes. Strings in I are converted to XML::Grove::Characters objects. =back =head2 ELEMENT FACTORY EXAMPLE use XML::Grove::Factory; $ef = XML::Grove::Factory->element_factory(); $element = $ef->HTML( $ef->HEAD( $ef->TITLE('Some Title')), $ef->BODY({ bgcolor => '#FFFFFF' }, $ef->P('A paragraph.'))); =head1 ELEMENT FUNCTIONS =over 4 =item XML::Grove::Factory->element_functions (PREFIX, ELEMENTS) Creates functions in the current package for creating elements with the names provided in the list I. I will be prepended to every function name, or I can be an empty string ('') if you're confident that there won't be any conflicts with functions in your package. =item I( I ) =item I( { I }, I ) =item II( I ) =item II( { I }, I ) Functions created for `C>' or `CI>' can be called to create XML::Grove::Element objects with the given I, I, and I. The hash containing I is optional if this element doesn't need attributes. Strings in I are converted to XML::Grove::Characters objects. =head2 ELEMENT FACTORY EXAMPLE use XML::Grove::Factory; XML::Grove::Factory->element_functions('', qw{ HTML HEAD TITLE BODY P }); $element = HTML( HEAD( TITLE('Some Title')), BODY({ bgcolor => '#FFFFFF' }, P('A paragraph.'))); =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us Inspired by the HTML::AsSubs module by Gisle Aas. =head1 SEE ALSO perl(1), XML::Grove(3). Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/IDs.pm0100664000175000017500000000445707004334705020737 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::IDs is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # $Id: IDs.pm,v 1.2 1999/08/17 15:01:28 kmacleod Exp $ # use strict; package XML::Grove::IDs; use Data::Grove::Visitor; sub new { my ($type, $name, $elements) = @_; $name = 'id' if(!defined $name); return (bless {Name => $name, Elements => $elements}, $type); } sub visit_document { my $self = shift; my $grove = shift; my $hash = shift; $grove->children_accept ($self, $hash); } sub visit_element { my $self = shift; my $element = shift; my $hash = shift; if(!$self->{Elements} or $self->{Elements}{$element->{Name}}) { my $id = $element->{Attributes}{$self->{Name}}; $hash->{$id} = $element if (defined $id); } $element->children_accept ($self, $hash); } ### ### Extend the XML::Grove::Document and XML::Grove::Element packages with our ### new function. ### package XML::Grove::Document; sub get_ids { my $self = shift; my $hash = {}; $self->accept(XML::Grove::IDs->new(@_), $hash); return $hash; } package XML::Grove::Element; sub get_ids { my $self = shift; my $hash = {}; $self->accept(XML::Grove::IDs->new(@_), $hash); return $hash; } 1; __END__ =head1 NAME XML::Grove::IDs - return an index of `id' attributes in a grove =head1 SYNOPSIS use XML::Grove::IDs; # Using get_ids method on XML::Grove::Document or XML::Grove::Element: $hash = $grove_object->get_ids($attr_name, $elements); # Using an XML::Grove::IDs instance: $indexer = XML::Grove::IDs->new($attr_name, $elements); my $hash = {}; $grove_object->accept($indexer, $hash); =head1 DESCRIPTION C returns a hash index of all nodes in a grove with an `id' attribute. The keys of the hash are the ID attribute value and the value at that key is the element. `C<$attr_name>' and `C<$elements>' are optional. The attribute name defaults to `C' if `C<$attr_name>' is not supplied. Indexing can be restricted to only certain elements, by name, by providing a hash containing NAME=>1 values. =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3), Data::Grove::Visitor(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/Path.pm0100664000175000017500000000623207004334705021145 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::Path is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # $Id: Path.pm,v 1.2 1999/08/17 15:01:28 kmacleod Exp $ # package XML::Grove::Path; use XML::Grove; use XML::Grove::XPointer; use UNIVERSAL; sub at_path { my $element = shift; # or Grove my $path = shift; $path =~ s|^/*||; my @path = split('/', $path); return (_at_path ($element, [@path])); } sub _at_path { my $element = shift; # or Grove my $path = shift; my $segment = shift @$path; # segment := [ type ] [ '[' index ']' ] # # strip off the first segment, finding the type and index $segment =~ m|^ ([^\[]+)? # - look for an optional type # by matching anything but '[' (?: # - don't backreference the literals \[ # - literal '[' ([^\]]+) # - index, any non-']' chars \] # - literal ']' )? # - the whole index is optional |x; my ($node_type, $instance, $match) = ($1, $2, $&); # issues: # - should assert that no chars come after index and before next # segment or the end of the query string $instance = 1 if !defined $instance; my $object = $element->xp_child ($instance, $node_type); if ($#$path eq -1) { return $object; } elsif (!$object->isa('XML::Grove::Element')) { # FIXME a location would be nice. die "\`$match' doesn't exist or is not an element\n"; } else { return (_at_path($object, $path)); } } package XML::Grove::Document; sub at_path { goto &XML::Grove::Path::at_path; } package XML::Grove::Element; sub at_path { goto &XML::Grove::Path::at_path; } 1; __END__ =head1 NAME XML::Grove::Path - return the object at a path =head1 SYNOPSIS use XML::Grove::Path; # Using at_path method on XML::Grove::Document or XML::Grove::Element: $xml_obj = $grove_object->at_path("/some/path"); # Using an XML::Grove::Path instance: $pather = XML::Grove::Path->new(); $xml_obj = $pather->at_path($grove_object); =head1 DESCRIPTION C returns XML objects located at paths. Paths are strings of element names or XML object types seperated by slash ("/") characters. Paths must always start at the grove object passed to `C'. C is B XPath, but it should become obsolete when an XPath implementation is available. Paths are like URLs /html/body/ul/li[4] /html/body/#pi[2] The path segments can be element names or object types, the objects types are named using: #element #pi #comment #text #cdata #any The `C<#any>' object type matches any type of object, it is essentially an index into the contents of the parent object. The `C<#text>' object type treats text objects as if they are not normalized. Two consecutive text objects are seperate text objects. =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/PerlSAX.pm0100664000175000017500000001524607004334705021534 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::PerlSAX is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: PerlSAX.pm,v 1.3 1999/08/17 15:01:28 kmacleod Exp $ # use strict; package XML::Grove::PerlSAX; use UNIVERSAL; use Data::Grove::Visitor; sub new { my $type = shift; my $self = ($#_ == 0) ? shift : { @_ }; return bless $self, $type; } sub parse { my $self = shift; die "XML::Grove::PerlSAX: parser instance ($self) already parsing\n" if (defined $self->{ParseOptions}); # If there's one arg and it's a subclass of Data::Grove, # then that's what we're parsing my $args; if (scalar (@_) == 1 && UNIVERSAL::isa($_[0], 'Data::Grove')) { $args = { Source => { Grove => shift } }; } else { $args = (scalar (@_) == 1) ? shift : { @_ }; } my $parse_options = { %$self, %$args }; $self->{ParseOptions} = $parse_options; # ensure that we have at least one source if (!defined $parse_options->{Source} || !(defined $parse_options->{Source}{Grove})) { die "XML::Grove::PerlSAX: no source defined for parse\n"; } # assign default Handler to any undefined handlers if (defined $parse_options->{Handler}) { $parse_options->{DocumentHandler} = $parse_options->{Handler} if (!defined $parse_options->{DocumentHandler}); } # ensure that we have a DocumentHandler if (!defined $parse_options->{DocumentHandler}) { die "XML::Grove::PerlSAX: no Handler or DocumentHandler defined for parse\n"; } # cache DocumentHandler in self for callbacks $self->{DocumentHandler} = $parse_options->{DocumentHandler}; if (ref($self->{Source}{Grove}) !~ /Document/) { $self->{DocumentHandler}->start_document( { } ); $parse_options->{Source}{Grove}->accept($self); return $self->{DocumentHandler}->end_document( { } ); } else { $self->{Source}{Grove}->accept($self); } # clean up parser instance delete $self->{ParseOptions}; delete $self->{DocumentHandler}; } sub _parse_self { my $grove = shift; my $self = ($#_ == 0) ? shift : { @_ }; bless $self, 'XML::Grove::PerlSAX'; if (ref($grove) !~ /Document/) { $self->{DocumentHandler}->start_document( { } ); $grove->accept($self); return $self->{DocumentHandler}->end_document( { } ); } else { return $grove->accept($self); } } sub visit_document { my $self = shift; my $grove = shift; $self->{DocumentHandler}->start_document($grove); $grove->children_accept($self); return $self->{DocumentHandler}->end_document($grove); } sub visit_element { my $self = shift; my $element = shift; $self->{DocumentHandler}->start_element($element); $element->children_accept($self); return $self->{DocumentHandler}->end_element($element); } sub visit_entity { my $self = shift; my $entity = shift; return $self->{DocumentHandler}->int_entity($entity); } sub visit_pi { my $self = shift; my $pi = shift; return $self->{DocumentHandler}->processing_instruction($pi); } sub visit_comment { my $self = shift; my $comment = shift; return $self->{DocumentHandler}->comment($comment); } sub visit_characters { my $self = shift; my $characters = shift; return $self->{DocumentHandler}->characters($characters); } package XML::Grove::Document; sub parse { goto &XML::Grove::PerlSAX::_parse_self; } package XML::Grove::Element; sub parse { goto &XML::Grove::PerlSAX::_parse_self; } 1; __END__ =head1 NAME XML::Grove::PerlSAX - an PerlSAX event interface for XML objects =head1 SYNOPSIS use XML::Grove::PerlSAX; $parser = XML::Grove::PerlSAX->new( [OPTIONS] ); $result = $parser->parse( [OPTIONS] ); # or $result = $xml_object->parse( [OPTIONS] ); =head1 DESCRIPTION C is a PerlSAX parser that generates PerlSAX events from XML::Grove objects. This man page summarizes the specific options, handlers, and properties supported by C; please refer to the PerlSAX standard in `C' for general usage information. =head1 METHODS =over 4 =item new Creates a new parser object. Default options for parsing, described below, are passed as key-value pairs or as a single hash. Options may be changed directly in the parser object unless stated otherwise. Options passed to `C' override the default options in the parser object for the duration of the parse. =item parse Parses a document. Options, described below, are passed as key-value pairs or as a single hash. Options passed to `C' override default options in the parser object. =back =head1 OPTIONS The following options are supported by C: Handler default handler to receive events DocumentHandler handler to receive document events Source hash containing the input source for parsing If no handlers are provided then all events will be silently ignored. If a single grove argument is passed to the `C' method, it is treated as if a `C' option was given with a `C' parameter. The `C' hash may contain the following parameters: Grove The grove object used to generate parse events.. =head1 HANDLERS The following events are generated by C. XML::Grove::PerlSAX passes the corresponding grove object as it's parameter so the properties passed to the handler are those that were used to create or were assigned to the grove. Please see the docs for the parser used to create the grove for a list of properties that were provided. =head2 DocumentHandler methods =over 4 =item start_document Receive notification of the beginning of a document. This is called from the XML::Grove::Document object before processing any document content. =item end_document Receive notification of the end of a document. This is called from the XML::Grove::Document object after processing all document content. =item start_element Receive notification of the beginning of an element. This is called from the XML::Grove::Element object before processing any element content. =item end_element Receive notification of the end of an element. This is called from the XML::Grove::Element object after processing all element content. =item characters Receive notification of character data. This is called from the XML::Grove::Characters object. =item processing_instruction Receive notification of a processing instruction. This is called from the XML::Grove::PI object. =item comment Receive notification of a comment. This is called from the XML::Grove::Comment object. =back =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/Sub.pm0100664000175000017500000000542407004334705021004 0ustar ardoardo# # Copyright (C) 1998, 1999 Ken MacLeod # XML::Grove::Sub is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # $Id: Sub.pm,v 1.3 1999/09/02 20:56:58 kmacleod Exp $ # use strict; package XML::Grove::Sub; use Data::Grove::Visitor; sub new { my $type = shift; return (bless {}, $type); } sub visit_document { my $self = shift; my $document = shift; my $sub = shift; return (&$sub($document, @_), $document->children_accept ($self, $sub, @_)); } sub visit_element { my $self = shift; my $element = shift; my $sub = shift; return (&$sub($element, @_), $element->children_accept ($self, $sub, @_)); } sub visit_entity { my $self = shift; my $entity = shift; my $sub = shift; return (&$sub($entity, @_)); } sub visit_pi { my $self = shift; my $pi = shift; my $sub = shift; return (&$sub($pi, @_)); } sub visit_comment { my $self = shift; my $comment = shift; my $sub = shift; return (&$sub($comment, @_)); } sub visit_characters { my $self = shift; my $characters = shift; my $sub = shift; return (&$sub($characters, @_)); } ### ### Extend the XML::Grove::Document and XML::Grove::Element packages with our ### new function. ### package XML::Grove::Document; sub filter { my $self = shift; my $sub = shift; return ($self->accept(XML::Grove::Sub->new, $sub, @_)); } package XML::Grove::Element; sub filter { my $self = shift; my $sub = shift; return ($self->accept(XML::Grove::Sub->new, $sub, @_)); } 1; __END__ =head1 NAME XML::Grove::Sub - run a filter sub over a grove =head1 SYNOPSIS use XML::Grove::Sub; # Using filter method on XML::Grove::Document or XML::Grove::Element: @results = $grove_object->filter(\&sub [, ...]); # Using an XML::Grove::Sub instance: $filterer = XML::Grove::Sub->new(); @results = $grove_object->accept($filterer, \&sub [, ...]); =head1 DESCRIPTION C executes a sub, the filter, over all objects in a grove and returns a list of all the return values from the sub. The sub is called with the grove object as it's first parameter and passing the rest of the arguments to the call to `C' or `C'. =head1 EXAMPLE The following filter will return a list of all `C' or `C' elements with an attribute `C' beginning with `C' or `C'. @results = $grove_obj->filter(sub { my $obj = shift; if ($obj->isa('XML::Grove::Element') && (($obj->{Name} eq 'foo') || ($obj->{Name} eq 'bar')) && ($obj->{Attributes}{'widget-no'} =~ /^[AB]/)) { return ($obj); } return (); }); =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3), Data::Grove::Visitor(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/Subst.pm0100664000175000017500000001214707004334705021353 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # XML::Grove::Subst is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # $Id: Subst.pm,v 1.3 1999/08/25 16:49:32 kmacleod Exp $ # use strict; package XML::Grove::Subst; sub new { my $class = shift; return bless {}, $class; } sub subst { my $self = shift; my $grove_fragment = shift; my $args = [ @_ ]; return ($grove_fragment->accept($self, $args)); } sub subst_hash { my $self = shift; my $grove_fragment = shift; my $args = shift; return ($grove_fragment->accept($self, $args)); } sub visit_document { my $self = shift; my $document = shift; my $contents = [ $document->children_accept ($self, @_) ]; return XML::Grove::Document->new( Contents => $contents ); } sub visit_element { my $self = shift; my $element = shift; my $name = $element->{Name}; if ($name eq 'SUB:key') { my $subst = $_[0]{$element->{Attributes}{'key'}}; if (ref($subst) eq 'ARRAY') { return @$subst; } else { if (ref($subst)) { return $subst; } else { return XML::Grove::Characters->new( Data => $subst ); } } } elsif ($name =~ /^SUB:(.*)$/) { my $subst = $_[0][$1 - 1]; if (ref($subst) eq 'ARRAY') { return @$subst; } else { if (ref($subst)) { return $subst; } else { return XML::Grove::Characters->new( Data => $subst ); } } } my $contents = [ $element->children_accept ($self, @_) ]; return XML::Grove::Element->new( Name => $name, Nttributes => $element->{Attributes}, Contents => $contents ); } sub visit_pi { my $self = shift; my $pi = shift; return $pi; } sub visit_characters { my $self = shift; my $characters = shift; return $characters; } ### ### Extend the XML::Grove::Document and XML::Grove::Element packages with our ### new function. ### package XML::Grove::Document; sub subst { my $self = shift; return (XML::Grove::Subst->new->subst($self, @_)); } sub subst_hash { my $self = shift; return (XML::Grove::Subst->new->subst_hash($self, @_)); } package XML::Grove::Element; sub subst { my $self = shift; return (XML::Grove::Subst->new->subst($self, @_)); } sub subst_hash { my $self = shift; return (XML::Grove::Subst->new->subst_hash($self, @_)); } 1; __END__ =head1 NAME XML::Grove::Subst - substitute values into a template =head1 SYNOPSIS use XML::Grove::Subst; # Using subst method on XML::Grove::Document or XML::Grove::Element: $new_grove = $source_grove->subst( ARGS ); $new_grove = $source_grove->subst_hash( ARG ); # Using an XML::Grove::Subst instance: $subster = XML::Grove::Subst->new(); $new_grove = $subster->subst( $source_grove, ARGS ); $new_grove = $subster->subst_hash( $source_grove, ARG ); =head1 DESCRIPTION C implements XML templates. C traverses through a source grove replacing all elements with names `C' or `C' with their corresponding values from ARGS (a list) or ARG (a hash), repsectively. =head1 METHODS =over 4 =item $grove_obj->subst( I ) =item $subster->subst( $grove_obj, I ) Search for `C>' elements, where I is an array index, and replace the element with the value from I, a list of values. The return value is a new grove with the substitutions applied. =item $grove_obj->subst_hash( I ) =item $subster->subst_hash( $grove_obj, I ) Search for `C' elements and replace the element with the value from I, a hash of values. The hash key is taken from the `C' attribute of the `C' element, for example, `CSUB:key key='foo'E>'. The return value is a new grove with the substitutions applied. =head1 EXAMPLE The following template, in a file `C', could be used for a simple parts database conversion to HTML: <SUB:key key='Name'>

Information for part number :

To use this template you would first parse it and convert it to a grove, and then use `C' every time you needed a new page: use XML::Parser::PerlSAX; use XML::Grove; use XML::Grove::Builder; use XML::Grove::Subst; use XML::Grove::PerlSAX; use XML::Handler::XMLWriter; # Load the template $b = XML::Grove::Builder->new(); $p = XML::Parser::PerlSAX->new( Handler = $b ); $source_grove = $p->parse( Source => { SystemId => 'template.xml' } ); # Apply the substitutions $new_grove = $source_grove->subst_hash( { Name => 'Acme DCX-2000 Filter', Number => 'N4728', Description => 'The Best' } ); # Write the new grove to standard output $w = XML::Handler::XMLWriter->new(); $wp = XML::Grove::PerlSAX->new( Handler => $w ); $wp->parse( Source => { Grove => $new_grove } ); =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/lib/XML/Grove/XPointer.pm0100664000175000017500000000433407004334705022022 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # XML::Grove::XPointer is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # $Id: XPointer.pm,v 1.2 1999/08/17 15:01:28 kmacleod Exp $ # use strict; package XML::Grove::XPointer; package XML::Grove::Document; sub xp_child { goto &XML::Grove::Element::xp_child; } package XML::Grove::Element; sub xp_child { my $self = shift; my $instance = shift; my $node_type = shift; my $look_for; if (defined($node_type) && substr($node_type, 0, 1) eq '#') { $node_type eq '#element' and do { $look_for = 'XML::Grove::Element' }; $node_type eq '#pi' and do { $look_for = 'XML::Grove::PI' }; $node_type eq '#comment' and do { $look_for = 'XML::Grove::Comment' }; $node_type eq '#text' and do { $look_for = 'XML::Grove::Characters' }; $node_type eq '#cdata' and do { $look_for = 'XML::Grove::CData' }; $node_type eq '#any' and do { $node_type = undef }; } elsif (defined($node_type)) { $look_for = 'element-name'; } my $contents = $self->{Contents}; my $object = undef; $instance--; # 0 based if (!defined $node_type) { $object = $contents->[$instance]; } elsif ($look_for eq 'element-name') { my $i_object; foreach $i_object (@$contents) { if (ref($i_object) eq 'XML::Grove::Element' && $i_object->{Name} eq $node_type && $instance-- == 0) { $object = $i_object; last; } } } else { my $i_object; foreach $i_object (@$contents) { if (ref($i_object) eq $look_for && $instance-- == 0) { $object = $i_object; last; } } } return $object; } 1; __END__ =head1 NAME XML::Grove::XPointer - deprecated module once intended for XPointer =head1 SYNOPSIS THIS MODULE IS USED BY XML::Grove::Path, it does not implement any current version of XPointer =head1 DESCRIPTION This module implements a very tiny portion of an old draft of XPointer. XML::Grove::Path still uses this module, but both modules will be obsolete when a real XPath and XPointer module become available. =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1), XML::Grove(3), XML::Grove::Path(3) Extensible Markup Language (XML) =cut libxml-grove-perl-0.46alpha.orig/COPYING0100664000175000017500000000165607004334705016463 0ustar ardoardoCopyright (C) 1998 Ken MacLeod. All rights reserved. XML-Grove is free software; you can redistribute it and/or modify it under the terms of the Artistic License distributed with Perl version 5.000 or (at your option) any later version. Please refer to the Artistic License that came with your Perl distribution for more details. The Artistic License should have been included in your distribution of Perl. It resides in the file named "Artistic" at the top-level of the Perl source tree (where Perl was downloaded/unpacked -- ask your system administrator if you dont know where this is). Alternatively, the current version of the Artistic License distributed with Perl can be viewed on-line on the World-Wide Web (WWW) from the following URL: http://www.perl.com/perl/misc/Artistic.html The latest version of Perl can be obtained on the World-Wide web (WWW) from the following URL: http://www.perl.com/CPAN/src/latest.tar.gz libxml-grove-perl-0.46alpha.orig/ChangeLog0100664000175000017500000000665007004334705017201 0ustar ardoardo1999-09-03 Ken MacLeod * t/factory.t: added * lib/XML/Grove/Factory.pm: added 1999-09-01 Ken MacLeod * lib/XML/Grove/Sub.pm (visit_document): changed $grove to $document 1999-08-24 Ken MacLeod * lib/XML/Grove/AsString.pm (attr_as_string): missing =over/=back * release 0.45alpha * lib/XML/Grove/Subst.pm (subst_hash): typo in POD 1999-08-17 Ken MacLeod * lib/XML/Grove/Subst.pm: add POD, add subst() and subst_hash() methods to XML::Grove::Document and XML::Grove::Element * lib/XML/Grove/XPointer.pm: deprecated, add POD * lib/XML/Grove/Sub.pm, lib/XML/Grove/Path.pm: add POD 1999-08-16 Ken MacLeod * lib/XML/Grove/Builder.pm, lib/XML/Grove/IDs.pm: add POD * lib/XML/Grove/AsString.pm: converted to mixed-case options (new): accept key, value pairs or hash (entity_map_filter, entity_map_options, entity_map, filter): removed * lib/XML/Grove/AsCanonXML.pm: converted to mixed-case options (new): accept key, value pairs or hash (comments): removed 1999-08-11 Ken MacLeod * examples/xml2eml/*: deleted, was dependent on XML::Grove::ToObjects 1999-08-10 Ken MacLeod * lib/XML/Grove/ToObjects.pm: deleted, replaced by XML::PatAct::ToObjects * lib/XML/Grove/PerlSAX.pm (parse): major changes to bring up to spec 1999-05-26 Ken MacLeod * MANIFEST, XML-Grove.spec: updated for moved alpha modules * DOM-ecmascript.pod: updated, removed references to Parent * alpha: removed; moved examples to `examples/' and modules to lib/XML/Grove * DOM: updated, added GetElementsByTagName and Normalize * lib/XML/Grove/Builder.pm (end_document): remove call to add_magic * lib/XML/Grove.pm: major doc update, remove emphasis on Data::Grove::Parent * DOM-ecmascript.pod: renamed occurrences of Perl SAX to PerlSAX * lib/XML/Grove/SAX.pm: rename to PerlSAX.pm * README: major update, move alpha modules here * alpha/xml2eml/xml2eml.pl: update to PerlSAX * alpha/lib/XML/Grove/Subst.pm (visit_element): return Characters object if substitute value is a scalar 1999-05-06 Ken MacLeod * lib/XML/Grove.pm, t/grove.t: rename SAXPerl to PerlSAX * lib/XML/Grove.pm: add $type_name class var to all classes * examples/grove.pl, examples/my-html.pl, examples/visitor.pl: convert to PerlSAX/Grove::Builder 1999-04-30 Ken MacLeod * Makefile.PL: added a PREREQ_PM for XML::Parser 1999-02-17 Ken MacLeod * lib/XML/Grove.pm: moved property set methods to libxml/lib/Data/Grove.pm * lib/XML/Grove/Node.pm: moved to libxml/lib/Data/Grove/Tied.pm * lib/XML/Grove/Visitor.pm: moved to libxml/lib/Data/Grove/Visitor.pm * lib/XML/Grove/Visitor.pm: dynamically check visitor to see if will accept callbacks 1999-02-16 Ken MacLeod * DOM-ecmascript.pod: added * lib/XML/Grove.pm: reformatted using better lists 1999-02-15 Ken MacLeod * lib/XML/Grove/Builder.pm: fix several bugs found with ESISParser; move Entities, Notations, AppInfo, and Conforming into XML::Grove::Document object * lib/XML/Grove.pm: minor doc fixes 1999-02-10 Ken MacLeod * lib/XML/Grove/Builder.pm (subdoc_start): fix typo in $contents assignment libxml-grove-perl-0.46alpha.orig/Changes0100664000175000017500000000462407004334705016721 0ustar ardoardoRevision history for Perl extension XML::Grove. Backwards incompatible changes are marked with a `*'. Changes in Version 1.0 Version 1.0 is virtually a complete rewrite. The summary below presents the changes as a bullet list, but you should probably reread the POD docs because they have been updated and should be much clearer than before (let me know if you don't think so!). * XML::Grove REQUIRES Perl 5.005 * The class structure of XML::Grove changes somewhat. * XML::Grove::Document now contains the document information where XML::Grove itself used to hold that information. * The class XML::Grove is now the common superclass of all classes in the XML::Grove module, and XML::Grove isa Data::Grove (in libxml-perl). * Internal class XML::Grove::_Common is gone. If you had created extensions to XML::Grove and added methods to XML::Grove::_Common, you should move them to XML::Grove. * You now access grove properties directly, i.e. $element_name = $element->{Name}; instead of using methods to access the properties. * XML::Grove objects all now appear to have Parent references. * This is done using tied hashes and arrays, see Data::Grove::Tied if you see any wierd problems. Use $real_object = $node->{Raw}; to get the real object behind the tied hash. * No More XML::Grove::Iter!! * all scalars are now XML::Grove::Characters objects, if you store a scalar value into element content it will be converted to an XML::Grove::Characters object. * visit_grove is now visit_document. * visit_scalar is now visit_characters. The object you receive is an XML::Grove::Characters object and $characters->{Data} gives you the text. * XML::Grove::Visitor is now Data::Grove::Visitor in libxml-perl * Visitor now checks the visitor object for methods it supports and silently ignores undefined methods. If the visited object has a `Contents' property, Visitor will call `children_accept' or `children_accept_name' if there is no defined method. * All properties are mixed case, see XML::Grove(3) and the grove builder and parser man pages for attribute names. * FIXME check all places where Iter, visit_scalar, and delegate occur. * XML::Parser::Grove is replaced by by using XML::Parser::PerlSAX (in libxml-perl) and XML::Grove::Builder. See XML::Grove::Builder for usage. * added more tests and a `t' directorylibxml-grove-perl-0.46alpha.orig/DOM0100664000175000017500000001120407004334705015760 0ustar ardoardo$Id: DOM,v 1.3 1999/05/26 15:42:16 kmacleod Exp $ These are some notes relating XML::Grove to the core Document Object Model (REC-DOM-Level-1-19981001). In theory it should be relatively easy to create a strict DOM interface that closely matches the DOM spec, I will keep such an interface in mind to avoid conflicting designs. On the left are DOM classes and methods and on the right are equivalent XML::Grove classes, methods, and notes. Equivalents marked with an asterisk (*) are available with the XML::Grove extensions Data::Grove::Parent, XML::Grove::Normalize, or XML::Grove::GetElementsByTagName. DOMImplementation No Equivalent boolean hasFeature(feature, version) DocumentFragment Any XML::Grove object can be a document fragment. Document XML::Grove::Document doctype not yet implemented implementation not yet implemented documentElement $grove->root (*) createXXX XXX->new getElementsByTagName $grove->get_elements_by_tag_name (*) `Node' in DOM is a superclass of all other nodes in DOM, `XML::Grove' is the superclass of all objects in the XML::Grove module. Node XML::Grove nodeName $element->{Name} nodeValue $element->{Value} nodeType use `ref()' and pattern matching (match /.*::TYPE(::.*)?$/) parentNode $obj->{Parent} (*) childNodes $obj->{Contents} firstChild $obj->{Contents}[0] lastChild $obj->{Contents}[-1] previousSibling no equivalent nextSibling no equivalent attributes $element->{Attributes} ownerDocument $obj->root->{Parent} (*) insertBefore splice(@{$node->{Contents}}, $index, 0, $new_child) replaceChild splice(@{$node->{Contents}}, $index, 1, $new_child) removeChild splice(@{$node->{Contents}}, $index, 1) appendChild push(@{$node->{Contents}}, $new_child) hasChildNodes $#{$node->{Contents}} != -1 cloneNode $new = $obj->clone() NodeList NodeLists are Perl arrays NamedNodeMap NamedNodeMap are Perl hashes CharacterData data $characters->{Data} Attr Attr are stored in Perl hashes, unspecified values are undef Element XML::Grove::Element getAttribute $element->{Attributes}{$name} setAttribute $element->{Attributes}{$name} = $value removeAttribute undef $element{Attributes}{$name} getAttributeNode no equivalent setAttributeNode no equivalent removeAttributeNode delete $element{Attributes}{$name} getElementsByTagName $elem->get_elements_by_tag_name (*) normalize $elem->normalize (*) Text data $characters->{Data} Comment XML::Grove::Comment data $comment->{Data} CDATASection XML::Grove::CData DocumentType see XML::Grove::Document Notation XML::Grove::Notation nodeName $notation->{Name} publicId $notation->{PublicId} systemId $notation->{SystemId} Entity XML::Grove::ExtEntity nodeName $ext_entity->{Name} publicId $ext_entity->{PublicId} systemId $ext_entity->{SystemId} notationName $ext_entity->{Notation}{Name} EntityReference XML::Grove::Entity nodeName $entity->{Name} nodeValue $entity->{Data} ProcessingInstruction XML::Grove::PI target $pi->{Target} data $pi->{Data} libxml-grove-perl-0.46alpha.orig/DOM-ecmascript.pod0100664000175000017500000000746407004334705020706 0ustar ardoardo=head1 XML::Grove and DOM Level One XML::Grove is similar in concept to the ECMA Script Language Binding to DOM Level 1 Core (Appendix E of the DOM Recommendation). The ECMA Script Language Binding presents DOM properties as ECMA Script object properties. The same is true for XML::Grove, XML::Grove presents DOM properties as Perl blessed hashes. The biggest difference between the ECMA Script Language Binding and XML::Grove is that XML::Grove uses a Perl hash for nodes, Perl arrays for NodeLists, Perl hashes for NamedNodeLists so those object classes don't exist in XML::Grove. Because those classes don't exist, you use ordinary Perl syntax for manipulating the DOM properties (lists and named node lists) instead of methods like `C' or `C'. Element attributes in XML::Grove are stored in Perl hashes; attribute types are available through the document object. Another difference is that XML::Grove attempts to marry the PerlSAX and DOM naming so that less (no?) name-changing occurs between using PerlSAX interfaces and filters and DOM modules. Where conflicts occur, the PerlSAX naming is used. XML::Grove uses a blessed hash for nodes, so the node type is available using Perl's `C' instead of using a `C' method and all class names are prefixed with `C'. The following object descriptions are the most basic and common provided by many PerlSAX parsers. PerlSAX parsers often provide additional properties or objects, refer to your PerlSAX parser documentation for details. =head1 Document Object Model Level 1 Core =head2 Object XML::Grove::Document =over 12 =item Contents The children of this object. This property is an array. =item Entities The entities declared in this document. This property is a hash of XML::Grove::Entity objects keyed by entity name. =item Notations The notations declared in this document. This property is a hash of XML::Grove::Notation objects keyed by notation name. =back =head2 Object XML::Grove::Element =over 12 =item Name The tag type name for this element. This property is a string. =item Attributes The attributes for this element. This property is a hash and it's hash values are strings (or arrays with some grove builders). =item Contents The children of this object. This property is an array of XML::Grove objects. =back =head2 Object XML::Grove::Characters =over 12 =item Data The text of the character data. This property is a string. =back =head2 Object XML::Grove::Comment =over 12 =item Data The text of the character data. This property is a string. =back =head2 Object XML::Grove::CData The C object is called a C in DOM. =over 12 =item Data The text of the character data. This property is a string. =back =head2 Object XML::Grove::Notation =over 12 =item Name The name of this notation. This property is a string. =item SystemId The system identifier of this notation. This property is a string. =item PublicId The public identifier of this notation. This property is a string. =back =head2 Object XML::Grove::Entity =over 12 =item Name The name of this entity. This property is a string. =item SystemId The system identifier of this notation. This property is a string. =item PublicId The public identifier of this notation. This property is a string. =item Notation The notation declared for this entity. This property is either the name of the notation as a string or an C object. =back =head2 Object XML::Grove::PI The C object is called a C in DOM. =over 12 =item Target The target of the processing instruction. This property is a string. =item Data The text of the processing instruction. This property is a string. =back libxml-grove-perl-0.46alpha.orig/MANIFEST0100664000175000017500000000105607004334705016553 0ustar ardoardoCOPYING ChangeLog Changes DOM DOM-ecmascript.pod MANIFEST Makefile.PL README XML-Grove.spec XML-Grove-0.46alpha.spec examples/README examples/grove.pl examples/my-html.html examples/my-html.pl examples/test-ids.pl examples/test-path.pl examples/test-sub.pl examples/visitor.pl lib/XML/Grove/AsCanonXML.pm lib/XML/Grove/AsString.pm lib/XML/Grove/Builder.pm lib/XML/Grove/Factory.pm lib/XML/Grove/IDs.pm lib/XML/Grove/Path.pm lib/XML/Grove/PerlSAX.pm lib/XML/Grove/Sub.pm lib/XML/Grove/Subst.pm lib/XML/Grove/XPointer.pm lib/XML/Grove.pm t/grove.t t/factory.t libxml-grove-perl-0.46alpha.orig/Makefile.PL0100664000175000017500000000074707004334705017402 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # See the file COPYING for distribution terms. # # $Id: Makefile.PL,v 1.2 1999/04/30 18:11:45 kmacleod Exp $ # use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'XML::Grove', 'VERSION_FROM' => 'lib/XML/Grove.pm', 'PREREQ_PM' => { 'XML::Parser' => '2.19' }, dist => {'COMPRESS' => 'gzip', 'SUFFIX' => '.gz'}, ); libxml-grove-perl-0.46alpha.orig/README0100664000175000017500000001172007004334705016301 0ustar ardoardo$Id: README,v 1.12 1999/09/03 21:41:00 kmacleod Exp $ XML::Grove A Perl 5 module providing simple access to the information set of parsed XML, HTML, or SGML instances. Ken MacLeod ken@bitsko.slc.ut.us INTRODUCTION XML::Grove provides simple access to the information set of parsed XML, HTML, or SGML instances using a tree of Perl hashes. This package also includes several extensions to XML::Grove that provide the following: * returning element contents as a string * returning element contents as XML, HTML, or Canonical XML * processing entire groves using the visitor pattern * processing entire groves using PerlSAX * running a filter over all nodes in the grove * substituting values into an XML template grove * indexing a grove by ID or other attributes * accessing elements and objects via URL-like paths * create grove objects using an easy shorthand See ``Using XML::Grove'' for an introduction to using XML::Grove. See the file Changes for user-visible changes. See the `examples' directory for examples of using XML::Grove. POD documentation is included in all non-alpha modules and scripts. You should also be able to use the 'perldoc' utility to extract documentation from the module files directly. HTML formatted docs are available at the XML::Grove home page . Newer versions of this module can be found on CPAN at . To join the Perl-XML mailing list, send an email message to ListManager@ActiveState.com with the following text in the body: Subscribe Perl-XML Copyright (C) 1998, 1999 Ken MacLeod XML::Grove is distributed under the same terms as Perl. See the file COPYING for distribution terms. MODULES The following modules are marked with their release status: STABLE -- has been in use for a while with few or no outstanding bugs BETA -- interfaces are stable but there may still be bugs ALPHA -- interfaces are changing, there may be lots of bugs, and there may not be docs available yet XML::Grove STABLE Declares all the XML::Grove object classes and provides a `new()' method for basic object creation. XML::Grove::Builder STABLE Builds entires groves from *ML instances using PerlSAX parsers. XML::Grove::AsString STABLE Adds `as_string()' methods to XML::Grove objects to return the character data of the object and any elements contained in the object. The string may optionally be filtered, have entity references mapped to different replacement text, or written to a file. XML::Grove::AsCanonXML STABLE Adds `as_canon_xml()' methods to XML::Grove objects to return a string or write objects to a file in ``Canonical XML'' format. Data::Grove::Visitor STABLE (in libxml-perl) Processes or ``walks' an entire grove by making callbacks to a class you define. Visitor calls your class once for every grove object (no start/end calls), allows arguments to be passed down during the walk, and you can stop any further processing below an element or other container. XML::Grove::PerlSAX STABLE Processes an entire grove by making callbacks to a class you define using the PerlSAX API. Calls start/end methods for container objects. PerlSAX can be used to provide input to SAX filters. Data::Grove::Parent STABLE (in libxml-perl) Adds a Parent property and `root()' and `rootpath()' methods to grove objects. XML::Grove::Factory BETA Provides objects and functions to easily create groves directly from Perl. XML::Grove::IDs BETA Return a hash mapping ID or other attributes to the elements where they are defined. XML::Grove::Path BETA Return an object in the grove using URL-like paths, e.g. `/html/head/title'. XML::Grove::Sub BETA Run a sub or filter across all objects in the grove. XML::Grove::XPointer DEPRECATED Implements a `xp_child()' method used by XML::Grove::Path. Does _not_ implement any current XPointer features. XML::Grove::ToObjects OBSOLETE Convert XML to Perl objects via a mapping table. Replaced by XML::PatAct::ToObjects in libxml-perl. INSTALLATION XML::Grove requires Perl 5.005 and libxml-perl. Most likely you will also want to get XML::Parser for reading XML documents. XML::Parser is available from CPAN: XML::Grove installs as a standard Perl module perl Makefile.PL make make test make install libxml-grove-perl-0.46alpha.orig/XML-Grove-0.46alpha.spec0100664000175000017500000000337507004334705021417 0ustar ardoardoSummary: Perl module for simple XML objects Name: XML-Grove Version: 0.46alpha Release: 1 Source: ftp://ftp.uu.net/vendor/bitsko/gdo/XML-Grove-0.46alpha.tar.gz Copyright: distributable Group: Applications/Publishing/XML URL: http://www.bitsko.slc.ut.us/ Packager: ken@bitsko.slc.ut.us (Ken MacLeod) BuildRoot: /tmp/XML-Grove # # $Id: XML-Grove.spec,v 1.16 1999/09/03 21:41:00 kmacleod Exp $ # %description XML::Grove is a Perl module that provides simple objects for parsed XML, SGML, and HTML documents. %prep %setup perl Makefile.PL INSTALLDIRS=perl %build make %install make PREFIX="${RPM_ROOT_DIR}/usr" pure_install DOCDIR="${RPM_ROOT_DIR}/usr/doc/XML-Grove-0.46alpha-1" mkdir -p "$DOCDIR/examples" "$DOCDIR/t" for ii in README COPYING Changes DOM DOM-ecmascript.pod t/* \ `find examples -type f -print`; do cp $ii "$DOCDIR/$ii" chmod 644 "$DOCDIR/$ii" done %files /usr/doc/XML-Grove-0.46alpha-1 /usr/lib/perl5/XML/Grove/AsCanonXML.pm /usr/lib/perl5/XML/Grove/AsString.pm /usr/lib/perl5/XML/Grove/Builder.pm /usr/lib/perl5/XML/Grove/Factory.pm /usr/lib/perl5/XML/Grove/IDs.pm /usr/lib/perl5/XML/Grove/Path.pm /usr/lib/perl5/XML/Grove/PerlSAX.pm /usr/lib/perl5/XML/Grove/Sub.pm /usr/lib/perl5/XML/Grove/Subst.pm /usr/lib/perl5/XML/Grove/XPointer.pm /usr/lib/perl5/XML/Grove.pm /usr/lib/perl5/man/man3/XML::Grove.3 /usr/lib/perl5/man/man3/XML::Grove::AsCanonXML.3 /usr/lib/perl5/man/man3/XML::Grove::AsString.3 /usr/lib/perl5/man/man3/XML::Grove::Builder.3 /usr/lib/perl5/man/man3/XML::Grove::Factory.3 /usr/lib/perl5/man/man3/XML::Grove::IDs.3 /usr/lib/perl5/man/man3/XML::Grove::Path.3 /usr/lib/perl5/man/man3/XML::Grove::PerlSAX.3 /usr/lib/perl5/man/man3/XML::Grove::Sub.3 /usr/lib/perl5/man/man3/XML::Grove::Subst.3 /usr/lib/perl5/man/man3/XML::Grove::XPointer.3 libxml-grove-perl-0.46alpha.orig/XML-Grove.spec0100664000175000017500000000337507004334705020024 0ustar ardoardoSummary: Perl module for simple XML objects Name: XML-Grove Version: @VERSION@ Release: 1 Source: ftp://ftp.uu.net/vendor/bitsko/gdo/XML-Grove-@VERSION@.tar.gz Copyright: distributable Group: Applications/Publishing/XML URL: http://www.bitsko.slc.ut.us/ Packager: ken@bitsko.slc.ut.us (Ken MacLeod) BuildRoot: /tmp/XML-Grove # # $Id: XML-Grove.spec,v 1.16 1999/09/03 21:41:00 kmacleod Exp $ # %description XML::Grove is a Perl module that provides simple objects for parsed XML, SGML, and HTML documents. %prep %setup perl Makefile.PL INSTALLDIRS=perl %build make %install make PREFIX="${RPM_ROOT_DIR}/usr" pure_install DOCDIR="${RPM_ROOT_DIR}/usr/doc/XML-Grove-@VERSION@-1" mkdir -p "$DOCDIR/examples" "$DOCDIR/t" for ii in README COPYING Changes DOM DOM-ecmascript.pod t/* \ `find examples -type f -print`; do cp $ii "$DOCDIR/$ii" chmod 644 "$DOCDIR/$ii" done %files /usr/doc/XML-Grove-@VERSION@-1 /usr/lib/perl5/XML/Grove/AsCanonXML.pm /usr/lib/perl5/XML/Grove/AsString.pm /usr/lib/perl5/XML/Grove/Builder.pm /usr/lib/perl5/XML/Grove/Factory.pm /usr/lib/perl5/XML/Grove/IDs.pm /usr/lib/perl5/XML/Grove/Path.pm /usr/lib/perl5/XML/Grove/PerlSAX.pm /usr/lib/perl5/XML/Grove/Sub.pm /usr/lib/perl5/XML/Grove/Subst.pm /usr/lib/perl5/XML/Grove/XPointer.pm /usr/lib/perl5/XML/Grove.pm /usr/lib/perl5/man/man3/XML::Grove.3 /usr/lib/perl5/man/man3/XML::Grove::AsCanonXML.3 /usr/lib/perl5/man/man3/XML::Grove::AsString.3 /usr/lib/perl5/man/man3/XML::Grove::Builder.3 /usr/lib/perl5/man/man3/XML::Grove::Factory.3 /usr/lib/perl5/man/man3/XML::Grove::IDs.3 /usr/lib/perl5/man/man3/XML::Grove::Path.3 /usr/lib/perl5/man/man3/XML::Grove::PerlSAX.3 /usr/lib/perl5/man/man3/XML::Grove::Sub.3 /usr/lib/perl5/man/man3/XML::Grove::Subst.3 /usr/lib/perl5/man/man3/XML::Grove::XPointer.3 libxml-grove-perl-0.46alpha.orig/examples/0042775000175000017500000000000007004335700017237 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/examples/README0100664000175000017500000000166307004334705020124 0ustar ardoardo$Id: README,v 1.3 1999/02/05 17:54:43 kmacleod Exp $ Copyright (C) 1998 Ken MacLeod See the file COPYING for distribution terms. Grove Examples The following examples are listed in concept order, starting with the first will lead into concepts in the later examples. All examples use XML::Parser. grove.pl Uses the simplest form of XML objects to recursively dump the object tree, similar to the `debug' style of XML::Parser. visitor.pl Uses a visitor class and callbacks to dump the tree. This is similar to the `sub' style of XML::Parser except that it uses generic `visit_element' callbacks instead of by-tag-name callbacks (see my-html.pl for that). my-html.pl, my-html.html Uses a visitor class and by-tag-name callbacks to add new tags to HTML-like documents. This example in particular shows one way to embed Perl code into HTML documents. libxml-grove-perl-0.46alpha.orig/examples/grove.pl0100664000175000017500000000267107004334705020723 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # See the file COPYING for distribution terms. # # $Id: grove.pl,v 1.4 1999/05/06 23:13:02 kmacleod Exp $ # use XML::Parser::PerlSAX; use XML::Grove; use XML::Grove::Builder; my $builder = XML::Grove::Builder->new; my $parser = XML::Parser::PerlSAX->new(Handler => $builder); my $doc; foreach $doc (@ARGV) { my $grove = $parser->parse (Source => { SystemId => $doc }); dump_grove ($grove); } sub dump_grove { my $grove = shift; my @context = (); _dump_contents ($grove->{Contents}, \@context); } sub _dump_contents { my $contents = shift; my $context = shift; foreach $item (@$contents) { if (ref ($item) =~ /::Element/) { push @$context, $item->{Name}; my @attributes = %{$item->{Attributes}}; print STDERR "@$context \\\\ (@attributes)\n"; _dump_contents ($item->{Contents}, $context); print STDERR "@$context //\n"; pop @$context; } elsif (ref ($item) =~ /::PI/) { my $target = $item->{Target}; my $data = $item->{Data}; print STDERR "@$context ?? $target($data)\n"; } elsif (ref ($item) =~ /::Characters/) { my $data = $item->{Data}; $data =~ s/([\x80-\xff])/sprintf "#x%X;", ord $1/eg; $data =~ s/([\t\n])/sprintf "#%d;", ord $1/eg; print STDERR "@$context || $data\n"; } elsif (!ref ($item)) { print STDERR "@$context !! SCALAR: $item\n"; } else { print STDERR "@$context !! OTHER: $item\n"; } } } libxml-grove-perl-0.46alpha.orig/examples/my-html.html0100664000175000017500000000167507004334705021524 0ustar ardoardo This is the title of my page

This is the body of my page.

This page was rendered on

Perl code can be used to generate any output you want. Here's a list of primes between 1 and 100.

libxml-grove-perl-0.46alpha.orig/examples/my-html.pl0100664000175000017500000000424107004334705021163 0ustar ardoardo# # Copyright (C) 1997, 1998 Ken MacLeod # See the file COPYING for distribution terms. # # $Id: my-html.pl,v 1.5 1999/05/06 23:13:02 kmacleod Exp $ # # `my-html.pl' uses `accept_name' methods to generate calls back using # an element's name instead of the generic `visit_element'. Because # we don't want to handle every single possible element name, Perl's # AUTOLOAD feature is used to pass through any elements we don't # handle. use XML::Parser::PerlSAX; use XML::Grove; use XML::Grove::Builder; use XML::Grove::AsString; use Data::Grove::Visitor; ($prog = $0) =~ s|.*/||g; die "usage: $prog HTML-DOC\n" if ($#ARGV != 0); my $builder = XML::Grove::Builder->new; my $parser = XML::Parser::PerlSAX->new(Handler => $builder); my $grove = $parser->parse (Source => { SystemId => @ARGV[0] }); $grove->accept_name (MyHTML->new); exit (0); ###################################################################### # # A Visitor package. # package MyHTML; use strict; use vars qw{$AUTOLOAD}; sub new { my $class = shift; return bless {}, $class; } sub visit_document { my $self = shift; my $grove = shift; $grove->children_accept_name ($self, @_); } sub visit_element { my $self = shift; my $element = shift; print "<$element->{Name}>"; $element->children_accept_name ($self, @_); print "{Name}>"; } sub visit_entity { my $self = shift; my $entity = shift; warn "is entity?\n"; print "&" . $entity->{Name} . ";"; } sub visit_characters { my $self = shift; my $characters = shift; my $data = $characters->{Data}; # FIXME do we need to translate special chars here? $data =~ tr/\r/\n/; print $data; } ###################################################################### # # My special HTML tags # sub visit_name_DATE { my $time = localtime; # use only non-breaking spaces $time =~ s/ /\ /g; print $time; } sub visit_name_PERL { my $self = shift; my $element = shift; # doesn't grok entities, be sure to use CDATA marked sections my $perl = $element->as_string; $perl =~ tr/\r//d; no strict; eval $perl; use strict; warn $@ if $@; } 1; libxml-grove-perl-0.46alpha.orig/examples/test-ids.pl0100664000175000017500000000134307004334705021330 0ustar ardoardo# # $Id: test-ids.pl,v 1.1 1999/05/26 15:42:16 kmacleod Exp $ # # This example parses each doc on the command line and prints all of # the IDs found in the doc, with their Perl hash references use XML::Parser; use XML::Parser::Grove; use XML::Grove; use XML::Grove::IDs; my $doc; my $id_maker = new XML::Grove::IDs; foreach $doc (@ARGV) { print "---- $doc ----\n"; my $parser = XML::Parser->new(Style => 'grove'); $parser->parsefile ($doc); my $grove = $parser->{Grove}; my $ids = $grove->get_ids; my $id; foreach $id (sort keys %$ids) { # prints the id and the hash reference to the element, not # pretty but this is just a test. # printing paths would be cool. print "$id - $ids->{$id}\n"; } } libxml-grove-perl-0.46alpha.orig/examples/test-path.pl0100664000175000017500000000150507004334705021505 0ustar ardoardo# # Look in Path.pm for path usage # use XML::Parser; use XML::Parser::Grove; use XML::Grove; use XML::Grove::Path; die "usage: test-path.pl XML-FILE [PATH ...]\n" if ($#ARGV == -1); my $doc = shift @ARGV; my $parser = XML::Parser->new(Style => 'grove'); $parser->parsefile ($doc); my $grove = $parser->{Grove}; my $path; foreach $path (@ARGV) { print "$path = " . $grove->at_path($path) . "\n"; } if ($doc =~ /REC-xml-19980210/) { $path = "/spec/header/title/[0]"; print "$path = " . $grove->at_path($path) . "\n"; $path = "/spec/header/pubdate/day/[0]"; print "$path = " . $grove->at_path($path) . "\n"; $path = "/spec/header/pubdate/month/[0]"; print "$path = " . $grove->at_path($path) . "\n"; $path = "/spec/header/pubdate/year/[0]"; print "$path = " . $grove->at_path($path) . "\n"; } libxml-grove-perl-0.46alpha.orig/examples/test-sub.pl0100664000175000017500000000122407004334705021340 0ustar ardoardouse XML::Parser; use XML::Parser::Grove; use XML::Grove; use XML::Grove::Sub; my $doc; my $filter = new Sub; foreach $doc (@ARGV) { my $parser = XML::Parser->new(Style => 'grove'); $parser->parsefile ($doc); my $grove = $parser->{Grove}; # this sub returns all the elements with a name containing the letter `d'. my $sub = sub { my ($object) = @_; if (ref($object) =~ /::Element/ && $object->{Name} =~ /d/i) { return ($object); } return (); }; my @matches = $grove->filter($sub); my $match; foreach $match (@matches) { # prints the element name of the match. print $match->{Name} . "\n"; } } libxml-grove-perl-0.46alpha.orig/examples/visitor.pl0100664000175000017500000000276307004334705021302 0ustar ardoardo# # Copyright (C) 1998 Ken MacLeod # See the file COPYING for distribution terms. # # $Id: visitor.pl,v 1.5 1999/05/06 23:13:02 kmacleod Exp $ # use XML::Parser::PerlSAX; use XML::Grove; use XML::Grove::Builder; use Data::Grove::Visitor; my $builder = XML::Grove::Builder->new; my $parser = XML::Parser::PerlSAX->new(Handler => $builder); my $visitor = new MyVisitor; my $doc; foreach $doc (@ARGV) { my $grove = $parser->parse (Source => { SystemId => $doc} ); my @context; $grove->accept ($visitor, \@context); } package MyVisitor; sub new { my $class = shift; return bless {}, $class; } sub visit_document { my $self = shift; my $grove = shift; $grove->children_accept ($self, @_); } sub visit_element { my $self = shift; my $element = shift; my $context = shift; push @$context, $element->{Name}; my @attributes = %{$element->{Attributes}}; print STDERR "@$context \\\\ (@attributes)\n"; $element->children_accept ($self, $context, @_); print STDERR "@$context //\n"; pop @$context; } sub visit_pi { my $self = shift; my $pi = shift; my $context = shift; my $target = $pi->{Target}; my $data = $pi->{Data}; print STDERR "@$context ?? $target($data)\n"; } sub visit_characters { my $self = shift; my $characters = shift; my $context = shift; my $data = $characters->{Data}; $data =~ s/([\x80-\xff])/sprintf "#x%X;", ord $1/eg; $data =~ s/([\t\n])/sprintf "#%d;", ord $1/eg; print STDERR "@$context || $data\n"; } libxml-grove-perl-0.46alpha.orig/t/0042775000175000017500000000000007004335700015664 5ustar ardoardolibxml-grove-perl-0.46alpha.orig/t/factory.t0100664000175000017500000000647107004334705017527 0ustar ardoardo# Hey, emacs! This is -*- perl -*- # # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' # # $Id: factory.t,v 1.1 1999/09/03 21:41:00 kmacleod Exp $ # ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..5\n"; } END {print "not ok 1\n" unless $loaded;} use XML::Grove; use XML::Grove::Factory; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): $gf = XML::Grove::Factory->grove_factory; $element = $gf->element('HTML', $gf->element('HEAD', $gf->element('TITLE', 'Some Title')), $gf->element('BODY', { bgcolor => '#FFFFFF' }, $gf->element('P', 'A paragraph.'))); print ((check_result($element)) ? "ok 2\n" : "not ok 2\n"); $ef = XML::Grove::Factory->element_factory(); $element = $ef->HTML( $ef->HEAD( $ef->TITLE('Some Title')), $ef->BODY({ bgcolor => '#FFFFFF' }, $ef->P('A paragraph.'))); print ((check_result($element)) ? "ok 3\n" : "not ok 3\n"); XML::Grove::Factory->element_functions('', qw{ HTML HEAD TITLE BODY P }); $element = HTML( HEAD( TITLE('Some Title')), BODY({ bgcolor => '#FFFFFF' }, P('A paragraph.'))); print ((check_result($element)) ? "ok 4\n" : "not ok 4\n"); $element = Factory_Test->doit(); print ((check_result($element)) ? "ok 5\n" : "not ok 5\n"); sub check_result { my $element = shift; if (ref($element) ne 'XML::Grove::Element') { warn "err 1\n"; return 0; } elsif ($element->{Name} ne 'HTML') { warn "err 2\n"; return 0; } elsif (ref($element->{Contents}[0]) ne 'XML::Grove::Element') { warn "err 3\n"; return 0; } elsif ($element->{Contents}[0]{Name} ne 'HEAD') { warn "err 4\n"; return 0; } elsif (ref($element->{Contents}[1]) ne 'XML::Grove::Element') { warn "err 5\n"; return 0; } elsif ($element->{Contents}[1]{Name} ne 'BODY') { warn "err 6\n"; return 0; } elsif ($element->{Contents}[1]{Attributes}{'bgcolor'} ne '#FFFFFF') { warn "err 7\n"; return 0; } elsif (ref($element->{Contents}[0]{Contents}[0]) ne 'XML::Grove::Element') { warn "err 8\n"; return 0; } elsif ($element->{Contents}[0]{Contents}[0]{Name} ne 'TITLE') { warn "err 9\n"; return 0; } elsif ($element->{Contents}[0]{Contents}[0]{Contents}[0]{Data} ne 'Some Title') { warn "err 10\n"; return 0; } elsif (ref($element->{Contents}[1]{Contents}[0]) ne 'XML::Grove::Element') { warn "err 11\n"; return 0; } elsif ($element->{Contents}[1]{Contents}[0]{Name} ne 'P') { warn "err 12\n"; return 0; } elsif ($element->{Contents}[1]{Contents}[0]{Contents}[0]{Data} ne 'A paragraph.') { warn "err 13\n"; return 0; } return 1; } # This package checks the ability to create functions inside the # class, I think package Factory_Test; sub doit { XML::Grove::Factory->element_functions('', qw{ HTML HEAD TITLE BODY P }); return HTML( HEAD( TITLE('Some Title')), BODY({ bgcolor => '#FFFFFF' }, P('A paragraph.'))); } libxml-grove-perl-0.46alpha.orig/t/grove.t0100664000175000017500000001560607004334705017202 0ustar ardoardo# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..5\n"; } END {print "not ok 1\n" unless $loaded;} use XML::Grove; use XML::Parser::PerlSAX; use XML::Grove::Builder; use XML::Grove::AsString; use XML::Grove::AsCanonXML; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): # TEST: grove building $grove_builder = XML::Grove::Builder->new; $p = new XML::Parser::PerlSAX Handler => $grove_builder; $g = $p->parse (<<'EOF'); ORD"> ]> The Old Testament ... The First Book of the Kings Commonly called The Third Book of the Kings ... Jezebel threatens Elijah And &Ahab; told &Jezebel; all that &Elijah; had done, and withal how he had slain all the prophets with the sword. Then &Jezebel; sent a messenger unto &Elijah;, saying, So let the gods do to me, and more also, if I make not thy life as the life of one of them by to morrow about this time. And when he saw that, he arose, and went for his life, and came to &Beersheba;, which belongeth to &Judah;, and left his servant there. &ParaMark; But he himself went a day's journey into the wilderness, and came and sat down under a juniper tree: and he requested for himself that he might die; and said, It is enough; now, O &God;, take away my life; for I am not better than my fathers. for himself, or for his life An angel ministers to him And as he lay and slept under a juniper tree, behold, then an angel touched him, and said unto him, Arise and eat. ... ... ... ... EOF print "ok 2\n"; # TEST: as_cannon_xml $expected = <<'EOF'; The Old Testament ... The First Book of the Kings Commonly called The Third Book of the Kings ... Jezebel threatens Elijah And Āʹhăb told Jĕzʹe-bĕl all that E˔-līʹjah had done, and withal how he had slain all the prophets with the sword. Then Jĕzʹe-bĕl sent a messenger unto E˔-līʹjah, saying, So let the gods do to me, and more also, if I make not thy life as the life of one of them by to morrow about this time. And when he saw that, he arose, and went for his life, and came to Bēʹer-shēʹbȧ, which belongeth to Jūʹdah, and left his servant there. ¶ But he himself went a day's journey into the wilderness, and came and sat down under a juniper tree: and he requested for himself that he might die; and said, It is enough; now, O LORD, take away my life; for I am not better than my fathers. for himself, or for his life An angel ministers to him And as he lay and slept under a juniper tree, behold, then an angel touched him, and said unto him, Arise and eat. ... ... ... ... EOF chop ($expected); $got = $g->as_canon_xml; print (($got eq $expected) ? "ok 3\n" : "not ok 3\n"); # TEST: as_string $expected = <<'EOF'; The Old Testament ... The First Book of the Kings Commonly called The Third Book of the Kings ... Jezebel threatens Elijah And Āʹhăb told Jĕzʹe-bĕl all that E˔-līʹjah had done, and withal how he had slain all the prophets with the sword. Then Jĕzʹe-bĕl sent a messenger unto E˔-līʹjah, saying, So let the gods do to me, and more also, if I make not thy life as the life of one of them by to morrow about this time. And when he saw that, he arose, and went for his life, and came to Bēʹer-shēʹbȧ, which belongeth to Jūʹdah, and left his servant there. ¶ But he himself went a day's journey into the wilderness, and came and sat down under a juniper tree: and he requested for himself that he might die; and said, It is enough; now, O LORD, take away my life; for I am not better than my fathers. for himself, or for his life An angel ministers to him And as he lay and slept under a juniper tree, behold, then an angel touched him, and said unto him, Arise and eat. ... ... ... ... EOF $got = $g->as_string; print (($got eq $expected) ? "ok 4\n" : "not ok 4\n"); # TEST: attr_as_string $got = $g->root->{Contents}[1]{Contents}[4]->attr_as_string ('id'); print (($got eq 'OneKings') ? "ok 5\n" : "not ok 5\n");