![]() |
![]() |
![]() |
||||||||||||||
| Creating < XTMPath, Manipulating Topic Map Data Structures < < Home | ||||||||||||||||
|
CreatingXTMPath was also thought as a simple means to create Topic Map data structures. To create a new topic with the type beer-brand, all that has to written is
my $XXXX = $xtmp->create (
'/topic[instanceOf/topicRef/@href = "#beer-brand"]');
The created topic would have been defined in AsTMa= as
t-00000001 (beer-brand)with some automatically generated topic id. As it is possible to specify a number of predicates in an XTMPath expression, we can also provide more information for the topic
my $XXXX = $xtmp->create (
'/topic
[@id = "xxxx"]
[instanceOf/topicRef/@href = "#beer-brand"]
[baseNameString = "XXXX"]
[occurrence/resourceRef/@href = "http://www.xxxx.com.au/home.asp"]
');
This would be equivalent to
XXXX (beer-brand) bn: XXXX oc: http://www.xxxx.com.au/home.asp Again, the XTM::Path module is also smart enough to make educated guesses on the interpolation of paths if they contain gaps. /topic/instanceOf/topicRef/@href would be the equivalent to /topic/instanceOf/@href because topicRef is the only element below /topic/instanceOf that has an attribute href. The predicates are all interpreted in the current search/create context. This can be rather useful when it comes to creating more complex structures like associations:
my $a = $xtmp->create(
'/association
[instanceOf/topicRef/@href = "#is-owned-by"]
[member
[roleSpec/topicRef/@href = "#owner"]
[topicRef/@href = "#foster-group"]
]
[member
[roleSpec/topicRef/@href = "#property"]
[topicRef/@href = "#VB"]
]
');
The association in object $a would be the same as if created via XTM:
<association>
<instanceOf>
<topicRef xlink:href="#is-owned-by"/>
</instanceOf>
<member>
<roleSpec>
<topicRef xlink:href="#owner"/>
</roleSpec>
<topicRef xlink:href="#foster-group"/>
</member>
<member>
<roleSpec>
<topicRef xlink:href="#property"/>
</roleSpec>
<topicRef xlink:href="#VB"/>
</member>
</association>
Once the association has been handled and an association object is created,
all predicates are interpreted on that hierarchical level. The brackets
around instanceOf/topicRef/@href create the association type without actually changing the
context. The following members are created on the same level.
As one can see from the creation of the members, the predicates can also be nested. Within one member we move the context one step down underneath the member element. These are created before generating the role and player for that member. The notable part is that predicates can contain other XTMPath expressions, including those with further predicates. In that we are following the assertion that an XTMPath expression should itself evaluate to true if applied to the generated object. The XTM::Path module is however not limited to only creating topics or associations. Any valid XTM data structure can be built. The following only creates a member which can be further processed:
my $member = $xtmp->create(
'/member
[roleSpec/topicRef/@href = "#owner"]
[topicRef/@href = "#foster-group"]
');
|
|||||||||||||||