XTM::Path is a Perl module with topic map management, XPath like retrieval and construction facility.
SYNOPSIS
use XTM::XML;
$tm = new XTM (tie => new XTM::XML (file => 'mymap.tm')); # binds variable to channel
use XTM::Path;
my $xtmp = new XTM::Path (default => $tm);
# find particular topics and print topic id
foreach my $t ($xtmp->find ('/topic[.//baseNameString/text() = "test"]')) {
print $t->id;
}
# same using find twice
foreach my $t ($xtmp->find ('/topic[.//baseNameString/text() = "test"]')) {
print $xtmp->find ('@id', $t);
}
# create a topic
$t = $xtmp->create ('topic[@id = "id0815"]');
# same but with baseName
$t = $xtmp->create ('topic[@id = "id0815"]/baseNameString[text() = "test"]');
# associations are always cumbersome
$a = $xtmp->create ('association[member
[roleSpec/topicRef/@href = "#role1"]
[topicRef/@href = "#player1"]]
[member
[roleSpec/topicRef/@href = "#role2"]
[topicRef/@href = "#player2"]]');
This class provides a simple way to drill down the XTM data structures by following an XPath like approach.
The XTM standard (http://www.topicmaps.org/xtm/) is used as the basis to formulate XTM-Path queries. To find a particular topic, for instance, you might use
/topic[.//baseNameString = "some name"]
It is important to note that this package will NOT work on the original XTM document (this might even not exist if the map is created via other means), but is instead using the XTM::base data structure. This implies that all querying is done after merging and consolidation has been done.
Obviously, XTM::Path cannot be a complete query language, but it is useful in many development situations where drilling down the data structure is a cumbersome exercise. Together with intelligent add methods in XTM::Memory and XTM::generic this should simplify drastically the access, creation and manipulation of XTM data structures.
Product's homepage
Requirements:
· Perl