Syndication-NITF
view release on metacpan or search on metacpan
=item *
Get an individual element:
my $head = $nitf->gethead;
=item *
Return a reference to an array of elements:
my $identifiedcontentlist = $head->getdocdata->getidentifiedcontentList;
The array can be referenced as @$identifiedcontentlist, or an individual element can be
referenced as $identifiedcontentlist->[N].
=item *
Return the size of a list of elements:
my $iclcount = $head->getdocdata->getidentifiedcontentCount;
=item *
Get an attribute of an element (as text):
my $href = $catalog->getHref;
=item *
package Syndication::NITF::head;
use Carp;
@ISA = qw( Syndication::NITF::GlobalAttributesNode );
sub _init {
my ($self, $node) = @_;
$self->{_singleElements}->{title} = OPTIONAL;
$self->{_multiElements}->{meta} = ZEROORMORE;
$self->{_singleElements}->{tobject} = OPTIONAL;
$self->{_singleElements}->{iim} = OPTIONAL;
$self->{_singleElements}->{docdata} = OPTIONAL;
$self->{_multiElements}->{pubdata} = ZEROORMORE;
$self->{_realname}->{revisionhistory} = "revision-history";
$self->{_multiElements}->{"revision-history"} = ZEROORMORE;
}
#
# Syndication::NITF::title -- document title
#
package Syndication::NITF::title;
use Carp;
@ISA = qw( Syndication::NITF::GlobalAttributesNode );
sub _init {
my ($self, $node) = @_;
$self->{_multiElements}->{ds} = ZEROORMORE;
$self->{_attributes}->{num} = REQUIRED; # IIM field number
$self->{_attributes}->{value} = IMPLIED; # IIM field value
}
#
# Syndication::NITF::docdata -- Document metadata
#
package Syndication::NITF::docdata;
use Carp;
@ISA = qw( Syndication::NITF::GlobalAttributesNode );
sub _init {
my ($self, $node) = @_;
$self->{_multiElements}->{correction} = ZEROORMORE;
$self->{_multiElements}->{evloc} = ZEROORMORE;
$self->{_realname}->{docid} = "doc-id";
$self->{_multiElements}->{"doc-id"} = ZEROORMORE;
$self->{_realname}->{dellist} = "del-list";
examples/NITFParser.pl view on Meta::CPAN
MAIN:
{
my $filename = $ARGV[0] || die "Usage: $0 <filename to parse>\n";
my $nitf = new Syndication::NITF($filename);
my $head = $nitf->gethead;
print "title is ".$head->gettitle->getText."\n";
&parseTobject($head->gettobject);
&parseDocData($head->getdocdata);
my $body = $nitf->getbody;
&parseBodyHead($body->getbodyhead);
foreach my $bodycontent ($body->getbodycontentList) {
&parseBodyContent($bodycontent);
}
&parseBodyEnd($body->getbodyend);
examples/NITFParser.pl view on Meta::CPAN
# so we will soon embed a copy of the IPTC subject codes and add some routines to handle them.
print " (".$subject->gettobjectsubjectrefnum.")\n";
# Is the IPR (info provider) the person who provides the subject codes or the
# person who categorises the story? Defaults to "IPTC" so I guess it's the former
my $ipr = $subject->gettobjectsubjectipr;
print " info provider is ".$ipr."\n" if $ipr;
$i++;
}
}
# "docdata" contains general metadata about this document.
sub parseDocData {
my ($docdata) = @_;
print "Parsing docdata:\n";
# docdata could contain one or more of:
# fixture --
# date.issue --
# date.release --
# date.expire --
# doc-scope --
# series --
# ed-msg --
# du-key --
# doc.copyright --
# doc.rights --
# key-list --
# identified-content (zero or more) --
# correction -- this story is a correction of another
foreach my $correction ($docdata->getcorrectionList) {
print " Document is a correction\n";
print " This document's ID string is ".$correction->getidstring."\n";
print " It corrects document with ID ".$correction->getregsrc."\n";
print " Message: ".$correction->getinfo."\n";
}
# evloc -- event location data
foreach my $evloc ($docdata->getevlocList) {
print " Document event location data:\n";
print " City: ".$evloc->getcity."\n" if $evloc->getcity;
print " County/district: ".$evloc->getcountydist."\n" if $evloc->getcountydist;
print " ISO country code: ".$evloc->getisocc."\n" if $evloc->getisocc;
print " State/province: ".$evloc->getstateprov."\n" if $evloc->getstateprov;
}
# doc-id -- document identification data
foreach my $docid ($docdata->getdocidList) {
print " Document ID info:\n";
print " This document's ID string is ".$docid->getidstring."\n";
print " Source document ID is ".$docid->getregsrc."\n";
}
# del-list -- delivery trail (like Path: in SMTP mail, I guess)
foreach my $delitem ($docdata->getdellistList) {
print " Delivery list item:\n";
print " Level number is ".$delitem->getlevelnumber."\n" if $delitem->getlevelnumber;
print " Source name is ".$delitem->getsrcname."\n" if $delitem->getsrcname;
}
# urgency -- importance of news item (1=most, 5=normal, 8=least)
foreach my $urgency ($docdata->geturgencyList) {
print " Document urgency is ".$urgency->getedurg."\n";
}
# fixture -- a named document which is refreshed periodically (eg a columnist)
foreach my $fixture ($docdata->getfixtureList) {
print " Fixture ID is ".$fixture->getfixid."\n";
}
# date.issue -- the date of issue of the document (default is date of receipt).
foreach my $dateissue ($docdata->getdateissueList) {
print " Date of issue is ".$dateissue->getnorm."\n";
}
# date.release -- the date/time that the document can be released (default is date of receipt).
foreach my $daterelease ($docdata->getdatereleaseList) {
print " Release (embargo) date is ".$daterelease->getnorm."\n";
}
# date.expire -- the date/time at which the story expires (default is infinity).
foreach my $dateexpire ($docdata->getdateexpireList) {
print " Expiry date is ".$dateexpire->getnorm."\n";
}
# doc-scope -- area that the document covers (usually geographic region)
foreach my $docscope ($docdata->getdocscopeList) {
print " Document scope is ".$docscope->getscope."\n";
}
# series -- Identifies article as part of a series
foreach my $series ($docdata->getseriesList) {
print " Document is part of a series:\n";
print " Series name: ".$series->getseriesname."\n";
print " Part ".$series->getseriespart." of ".$series->getseriestotalpart."\n";
}
# ed-msg -- non-publishable editorial message about the news item
foreach my $edmsg ($docdata->getedmsgList) {
print " Editor's message: ";
print " Type: ".$edmsg->getmsgtype."\n";
print " Message: ".$edmsg->getinfo."\n";
}
# du-key -- Dynamic Use key: semi-unique ID generated by provider, attached to a story for all
# instances. Presumably used to update a story over time.
foreach my $dukey ($docdata->getdukeyList) {
print " Dynamic Use (du) key: ";
print " Key = ".$dukey->getkey."\n";
print " Generation = ".$dukey->getgeneration."\n";
print " Part = ".$dukey->getpart."\n";
print " Version = ".$dukey->getversion."\n";
}
# doc-copyright -- Copyright info: "should be consistent with information in the copyrite tag"
foreach my $doccopyright ($docdata->getdoccopyrightList) {
print " Document copyright info: ";
print " Holder = ".$doccopyright->getholder."\n";
print " Year = ".$doccopyright->getyear."\n";
}
# doc-rights -- Rights holder info:
# "should be consistent with information in the series of rights tags"
foreach my $docrights ($docdata->getdocrightsList) {
print " Document rights holder info: ";
print " Agent = ".$docrights->getagent."\n";
print " Code-source = ".$docrights->getcodesource."\n";
print " enddate = ".$docrights->getenddate."\n";
print " geography = ".$docrights->getgeography."\n";
print " limitations = ".$docrights->getlimitations."\n";
print " location-code = ".$docrights->getlocationcode."\n"; # "from standard list"
print " owner = ".$docrights->getowner."\n";
print " startdate = ".$docrights->getstartdate."\n";
print " type = ".$docrights->gettype."\n";
}
# key-list -- List of keywords
foreach my $keylist ($docdata->getkeylistList) {
print " Keyword list:\n";
foreach my $keyword ($keylist->getkeywordList) {
print " Keyword = ".$keyword->getkey."\n";
}
}
# identified-content -- Content identifiers for this document
foreach my $contentid ($docdata->getidentifiedcontentList) {
print " Content identifiers:\n";
foreach my $person ($contentid->getpersonList) {
&parsePerson($person);
}
foreach my $org ($contentid->getorgList) {
&parseOrg($org);
}
foreach my $location ($contentid->getlocationList) {
&parseLocation($location);
t/2_simple.t view on Meta::CPAN
# test 6: type of first component is what we want
ok($tobject->gettobjectsubjectList->[0]->gettobjectsubjecttype, "Weather");
# test 7: ref num of second component is what we want
ok($tobject->gettobjectsubjectList->[1]->gettobjectsubjectrefnum, "04001002");
# test 8: detail of second component is what we want
ok($tobject->gettobjectsubjectList->[1]->gettobjectsubjectdetail, "Fishing Industry");
my $docdata = $head->getdocdata;
# test 9: location code
ok($docdata->getidentifiedcontentList->[0]->getlocationList->[0]->getlocationcode, "23602");
# test 10: code source
ok($docdata->getidentifiedcontentList->[0]->getlocationList->[0]->getcodesource, "zipcodes.usps.gov");
my $body = $nitf->getbody;
my $bodyhead = $body->getbodyhead;
# test 11: "hedline" hl1
ok($bodyhead->gethedline->gethl1->getText, "Weather and Tide Updates for Norfolk");
# test 12: "hedline" hl2 (is a list)
ok($bodyhead->gethedline->gethl2List->[0]->getText, "A sample, fictitious NITF article");
t/test_data/nitf-fishing.xml view on Meta::CPAN
<tobject tobject.type="news">
<tobject.subject
tobject.subject.refnum="17000000"
tobject.subject.type="Weather"
/>
<tobject.subject
tobject.subject.refnum="04001002"
tobject.subject.detail="Fishing Industry"
/>
</tobject>
<docdata>
<identified-content>
<location
location-code="23602"
code-source="zipcodes.usps.gov"
/>
</identified-content>
</docdata>
</head>
<body>
<body.head>
<hedline>
<hl1>Weather and Tide Updates for Norfolk</hl1>
<hl2>A sample, fictitious NITF article</hl2>
</hedline>
<note><body.content><p>This sample article was created completely from scratch in order to
illustrate various features of NITF.
Parts of it are somewhat contrived, in order to illustrate as much
( run in 0.615 second using v1.01-cache-2.11-cpan-454fe037f31 )