NAME
Xacobeo::Document - An XML document and it's related information.
SYNOPSIS
use Xacobeo::Document;
my $document = Xacobeo::Document->new('file.xml');
my $namespaces = $document->namespaces(); # Hashref
while (my ($uri, $prefix) = each %{ $namespaces }) {
printf "%-5s: %s\n", $prefix, $uri;
}
my $nodes = $document->find('/x:html//x:a[@href]');
foreach my $node ($nodes->get_nodelist) {
print "Got node ", $node->name, "\n";
}
$document->validate('/x:html//x:a[@href]') or die "Invalid XPath expression";
DESCRIPTION
This package wraps an XML document with it's corresponding meta information (namespaces, source, etc).
METHODS
The package defines the following methods:
new
Creates a new instance.
Parameters:
$source: the source of the XML document, this can be a file name.
find
Runs the given XPath query on the document and returns the results. The results could be a node list or a single value like a boolean, a number or a scalar if an expression is passed. This method always return its values in scalar context.
This method croaks if the expression can't be evaluated.
Parameters:
$xpath: the XPath expression to execute.
validate
Validates the syntax of the given XPath query. The syntax is validated within a context that has the same namespaces as the ones defined in the current XML document.
NOTE: This method can't validate if undefined functions or variables are used.
Parameters:
$xpath: the XPath expression to validate.
get_prefixed_name
Returns the node name by prefixing it with our prefixes in the case where namespaces are used.
namespaces
Returns the namespaces declared in the document. The namespaces are returned in a hash REF where the URIs are used as a key and the prefix as a value.
AUTHORS
Emmanuel Rodriguez <potyl@cpan.org>.
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Emmanuel Rodriguez.
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.8 or, at your option, any later version of Perl 5 you may have available.