NAME

XML::DOM::XML_Base - Apply xml:base to attribute values.

SYNOPSIS

  use XML::DOM::XML_Base;
  my $parser = XML::DOM::Parser->new();

  my $xml = qq(
    <ecto x="1" xml:base="a/">
      <meso x="2" xml:base="b/">
        <endo x="3" xml:base="c/"/>
      </meso>
    </ecto>
  );

  # build the DOM
  my $dom = $parser->parse( $xml );

  # get some elements
  my $endo = $dom->getElementsByTagName( 'endo' )->item( 0 );
  my $meso = $dom->getElementsByTagName( 'meso' )->item( 0 );
  my $ecto = $dom->getElementsByTagName( 'ecto' )->item( 0 );

  print $endo->getBase()."\n"; # a/b/c/
  print $meso->getBase()."\n"; # a/b/
  print $ecto->getBase()."\n"; # a/

  print $endo->getAttributeWithBase( 'x' )."\n"; # a/b/c/3
  print $meso->getAttributeWithBase( 'x' )."\n"; # a/b/2
  print $ecto->getAttributeWithBase( 'x' )."\n"; # a/1

DESCRIPTION

XML::DOM::XML_Base implements the W3C XML Base specification as an extension to XML::DOM.

XML Base spec (http://www.w3.org/TR/xmlbase/) says: The rules for determining the base URI can be summarized as follows (highest priority to lowest):

  [1] The base URI is embedded in the document's content.
  [2] The base URI is that of the encapsulating entity (message, document, or none).
  [3] The base URI is the URI used to retrieve the entity.
  [4] The base URI is defined by the context of the application.

Rules [1] and [2] and handled by this module by recursively examining parent nodes for xml:base attributes, and returning the first constructable absolute URI, or the relative URI constructed at the end of the recursion (i.e. at the root XML element).

Rules [3] and [4] are outside the scope of what XML::DOM::XML_Base is capable of, as an XML::DOM::Document can be constructed without a URI (e.g. from a string or filehandle).

SEE ALSO

URI, XML::DOM

XML Base Specification (http://www.w3.org/TR/xmlbase/)

XML Base Tutorial (http://www.zvon.org/xxl/XMLBaseTutorial/Output/)

AUTHOR

Allen Day, <allenday@ucla.edu>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Allen Day

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.