Lab::Data::XMLtree - Handle and store XML and perl data structures with precise declaration.
use Lab::Data::XMLtree;
my $data_declaration = {
info => [# type B
'SCALAR',
{
basename => ['PSCALAR'],# type A
title => ['SCALAR'],# type A
place => ['SCALAR']# type A
}
],
column => [# type K
'ARRAY',
'id',
{
# PSCALAR means that this element will not
# be saved. Does not work for YAML yet.
min => ['PSCALAR'],# type A
max => ['PSCALAR'],# type A
description => ['SCALAR']# type A
}
],
axis => [# type F
'HASH',
'label',
{
unit => ['SCALAR'],# type A
logscale => ['SCALAR'],# type A
description => ['SCALAR']# type A
}
]
};
#create Lab::Data::XMLtree object from file
$data=Lab::Data::XMLtree->read_xml($data_declaration,'filename.xml');
#the autoloader
# get
print $data->info_title;
# get with $id
print $data->column_description($id);
# set with $key and $value
$data->axis_description($label,'descriptiontext');
#save data as YAML
$data->save_yaml('filename.yaml');
Lab::Data::XMLtree will take you to similar spots as XML::Simple does, but in a bigger bus and with fewer wild animals.
That's not a bad thing. You get more control of the data transformation processes and you get some extra functionality.
Lab::Data::XMLtree uses a data declaration, that describes, what the perl data structure looks like, and how this data structure is converted to XML.
Create a new Lab::Data::XMLtree. $data must be hashref and should match the declaration. Returns Lab::XMLtree object.
The first two elements define the folding behaviour.
Element occurs zero or one time. No folding necessary.
Examples:
$data->{dataset_title}='content';
Element occurs zero or more times. Folding will be done using an array reference. If $id is given, this XML element will be used as an id.
Example:
$data->{column}->[4]->{label}='testlabel';
Element occurs zero or more times. Folding will be done using a hash reference. If $key is given, this XML element will be used as a key.
Example:
$data->{axis}->{gate voltage}->{unit}="mV";
Opens a XML file $filename. Returns Lab::Data::XMLtree object.
Opens a YAML file $filename. Returns Lab::Data::XMLtree object.
Merge another Lab::Data::XMLtree into this one. Other tree must not necessarily be blessed.
Saves the tree as XML to $filename.
Saves the tree as YAML to $filename. PSCALAR etc. don't work yet.
Returns a stringified version of the object. (Using Data::Dumper.)
Get/set anything you want. Accounts the data declaration.
Lab::Data::XMLtree does not support all possible kinds of perl data structures. It is also not too flexible when it comes to XML. It simply supports something that I needed.
Lab::Data::XMLtree is similar to XML::Simple (XML::Simple).
Lab::Data::XMLtree can use XML::DOM (XML::DOM) to retrieve stored data.
Lab::XMLtree can use XML::Generator (XML::Generator) to store data as XML.
Lab::XMLtree can use YAML (YAML) for data storage.
Copyright 2004-2006 Daniel Schröer (http://www.danielschroeer.de), 2011 Andreas K. Hüttel
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.