NAME

xDT::Parser - A Parser for xDT files.

VERSION

Version 1.05

SYNOPSIS

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

ATTRIBUTES

fh

FileHandle to the currently open file.

record_type_config

The RecordType configurations.

e.g.:

[{
    "id": "0201",
    "length": "9",
    "type": "num",
    "accessor": "bsnr",
    "labels": {
        "en": "BSNR",
        "de": "BSNR"
    }
}]

SUBROUTINES/METHODS

open

$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/.

close

Closes the parsers filehandle

next_object

Returns the next object from xDT.

build_config_from_xml

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>

AUTHOR

Christoph Beger, <christoph.beger at medizin.uni-leipzig.de>