xDT::Parser - A Parser for xDT files.
Version 1.06
Can be used to open xdt files and strings, and to iterate over contained objects.
use xDT::Parser; my $parser = xDT::Parser->new(); # or my $parser = xDT::Parser->new(record_type_config => $config); # or my $parser = xDT::Parser->new( record_type_config => xDT::Parser::build_config_from_xml($xml_file) ); # or my $parser = xDT::Parser->new( record_type_config => JSON::Parser::read_json($json_file) ); # A record type configuration can be provided via xml file or arrayref and can be used to add # metadata (like accessor string or labels) to each record type. $parser->open(file => $xdt_file); # read from file # or $parser->open(string => $xdt_string); # read from string while (my $object = $parser->next_object) { # iterate xdt objects # ... } $parser->close(); # close the file handle
FileHandle to the currently open file.
The RecordType configurations.
RecordType
e.g.:
[{ "id": "0201", "length": "9", "type": "num", "accessor": "bsnr", "labels": { "en": "BSNR", "de": "BSNR" } }]
$parser->open(file => 'example.gdt'); $parser->open(string => $xdt_string);
Open a file or string with the parser. If both file and string are given, the string will be ignored. More information about the file format can be found at http://search.cpan.org/dist/xDT-RecordType/.
Closes the parsers filehandle
Returns the next object from xDT.
Extracts metadata for a given record type id from a XML config file, if a file was given. Otherwise id and accessor are set to the given id and all other attributes are undef.
XML::Simple must be installed in order to use this method.
Format of the XML config file:
<RecordTypes> <RecordType id="theId" length="theLength" type="theType" accessor="theAccessor"> <label lang="en">TheEnglishLabel</label> <label lang="de">TheGermanLabel</label> <!-- more labels --> </RecordType> <!-- more record types --> </RecordTypes>
Christoph Beger, <christoph.beger at medizin.uni-leipzig.de>
<christoph.beger at medizin.uni-leipzig.de>
To install xDT::Parser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm xDT::Parser
CPAN shell
perl -MCPAN -e shell install xDT::Parser
For more information on module installation, please visit the detailed CPAN module installation guide.