The Perl Advent Calendar needs more articles for 2022. Submit your idea today!


XML::CAP - parse or generate the XML Common Alerting Protocol (CAP)


Version 0.02


XML::CAP parses and generates XML Common Alerting Protocol (CAP).

More information about CAP can be found at

Each XML CAP structure has an "alert" section. Each alert may contain zero (usually one) or more "info" sections. Each info section may contain zero or more "resource" and/or "area" sections. Each area section may contain zero or more "geocode" sections. All of these sections are represented by subclasses of XML::CAP.

XML::CAP uses XML::LibXML. There are accessor functions for every element. But using the elem() method, there is also direct access to the corresponding LibXML node.

Code sample:

    use XML::CAP;
    use XML::CAP::Parser;

    my $parser = XML::CAP::Parser->new();
    $parser->parse_file( "cap-file.xml" );
    my $alert;
    eval_wrapper ( sub { $alert = $parser->alert });

    @alert_nodes = $alert->elem->childnodes; # access to XML::libXML data
    $identifier = $alert->identifier;
    $sender = $alert->sender;
    $sent = $alert->sent;
    $status = $alert->status;
    $msgType = $alert->msgType;
    $source = $alert->source;
    $scope = $alert->scope;
    $restriction = $alert->restriction;
    $addresses = $alert->addresses;
    $code = $alert->code;
    $note = $alert->note;
    $references = $alert->references;
    $incidents = $alert->incidents;

    my @infos = $alert->infos;
    @info_nodes = $infos[0]->elem->childnodes; # access LibXML data
    my $info = $infos[0];
    $language = $info->language;
    $category = $info->category;
    $event = $info->event;
    $responseType = $info->responseType;
    $urgency = $info->urgency;
    $severity = $info->severity;
    $certainty = $info->certainty;
    $audience = $info->audience;
    $eventCode = $info->eventCode;
    $effective = $info->effective;
    $onset = $info->onset;
    $expires = $info->expires;
    $senderName = $info->senderName;
    $headline = $info->headline;
    $description = $info->description;
    $instruction = $info->instruction;
    $web = $info->web;
    $contact = $info->contact;
    $parameter = $info->parameter;

    my @resources = $info->resources;
    @resource_nodes = $resources[0]->elem->childnodes; # access LibXML data
    my $resource = $resources[0];
    $resourceDesc = $resource->resourceDesc;
    $mimeType = $resource->mimeType;
    $size = $resource->size;
    $uri = $resource->uri;
    $derefUri = $resource->derefUri;
    $digest = $resource->digest;

    my @areas = $info->areas;
    @area_nodes = $areas[0]->elem->childnodes; # access LibXML data
    my $area = $areas[0];
    $areaDesc = $area->areaDesc;
    $polygon = $area->polygon;
    $circle = $area->circle;
    $altitude = $area->altitude;

    my @geocodes = $area->geocodes;
    @geocode_nodes = $geocodes[0]->elem->childnodes; # access LibXML data
    my $geocode = $geocodes[0];
    $valueName = $geocode->valueName;
    $value = $geocode->value;




eval_wrapper ( $code, $throw_func, [ name => value, ...] )


Ian Kluft, <ikluft at>


Please report any bugs or feature requests to bug-xml-cap at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc XML::CAP

You can also look for information at:


The initial version was derived from XML::Atom by Benjamin Trott and Tatsuhiko Miyagawa.


Copyright 2009 Ian Kluft, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.