home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl5 / XML / Grove / XPointer.pm < prev   
Encoding:
Text File  |  1999-10-23  |  2.2 KB  |  100 lines

  1. #
  2. # Copyright (C) 1998 Ken MacLeod
  3. # XML::Grove::XPointer is free software; you can redistribute it
  4. # and/or modify it under the same terms as Perl itself.
  5. #
  6. # $Id: XPointer.pm,v 1.2 1999/08/17 15:01:28 kmacleod Exp $
  7. #
  8.  
  9. use strict;
  10.  
  11. package XML::Grove::XPointer;
  12.  
  13. package XML::Grove::Document;
  14.  
  15. sub xp_child {
  16.     goto &XML::Grove::Element::xp_child;
  17. }
  18.  
  19. package XML::Grove::Element;
  20.  
  21. sub xp_child {
  22.     my $self = shift;
  23.     my $instance = shift;
  24.     my $node_type = shift;
  25.  
  26.     my $look_for;
  27.     if (defined($node_type) && substr($node_type, 0, 1) eq '#') {
  28.     $node_type eq '#element' and do { $look_for = 'XML::Grove::Element' };
  29.         $node_type eq '#pi'      and do { $look_for = 'XML::Grove::PI' };
  30.         $node_type eq '#comment' and do { $look_for = 'XML::Grove::Comment' };
  31.     $node_type eq '#text'    and do { $look_for = 'XML::Grove::Characters' };
  32.     $node_type eq '#cdata'   and do { $look_for = 'XML::Grove::CData' };
  33.     $node_type eq '#any'     and do { $node_type = undef };
  34.     } elsif (defined($node_type)) {
  35.     $look_for = 'element-name';
  36.     }
  37.  
  38.     my $contents = $self->{Contents};
  39.     my $object = undef;
  40.  
  41.     $instance--;        # 0 based
  42.  
  43.     if (!defined $node_type) {
  44.     $object = $contents->[$instance];
  45.     } elsif ($look_for eq 'element-name') {
  46.     my $i_object;
  47.     foreach $i_object (@$contents) {
  48.         if (ref($i_object) eq 'XML::Grove::Element'
  49.         && $i_object->{Name} eq $node_type
  50.         && $instance-- == 0) {
  51.         $object = $i_object;
  52.         last;
  53.         }
  54.     }
  55.     } else {
  56.     my $i_object;
  57.     foreach $i_object (@$contents) {
  58.         if (ref($i_object) eq $look_for
  59.         && $instance-- == 0) {
  60.         $object = $i_object;
  61.         last;
  62.         }
  63.     }
  64.     }
  65.  
  66.     return $object;
  67. }
  68.  
  69. 1;
  70.  
  71. __END__
  72.  
  73. =head1 NAME
  74.  
  75. XML::Grove::XPointer - deprecated module once intended for XPointer
  76.  
  77. =head1 SYNOPSIS
  78.  
  79.  THIS MODULE IS USED BY XML::Grove::Path, it does not implement any
  80.  current version of XPointer
  81.  
  82. =head1 DESCRIPTION
  83.  
  84. This module implements a very tiny portion of an old draft of
  85. XPointer.  XML::Grove::Path still uses this module, but both modules
  86. will be obsolete when a real XPath and XPointer module become
  87. available.
  88.  
  89. =head1 AUTHOR
  90.  
  91. Ken MacLeod, ken@bitsko.slc.ut.us
  92.  
  93. =head1 SEE ALSO
  94.  
  95. perl(1), XML::Grove(3), XML::Grove::Path(3)
  96.  
  97. Extensible Markup Language (XML) <http://www.w3c.org/XML>
  98.  
  99. =cut
  100.