AnyData
view release on metacpan or search on metacpan
lib/AnyData/Format/XML.pm view on Meta::CPAN
# $str = defined $fh ? $self->{twig}->print($fh)
# : $self->{twig}->sprint();
if($file and defined $fh ){ $str = $self->{twig}->print($fh) }
else {$str = $self->{twig}->sprint();}
undef $storage->{fh};
return $str;
}
1;
=head1 NAME
AnyData::Format::XML - tiedhash and DBI access to XML
=head1 SYNOPSIS
# access XML data via a multidimensional tied hash
# see AnyData.pod for full details
#
use AnyData;
my $table = adTie( 'XML', $file, $mode, $flags );
OR
# convert data to and from XML
# see AnyData.pod for full details
#
use AnyData;
adConvert( 'XML', $file1, $any_other_format, $file2, $flags );
adConvert( $any_other_format, $file1, 'XML', $file2, $flags );
OR
# access the data via DBI and SQL
# see DBD::AnyData.pod for full details
#
use DBI;
my $dbh = DBI->connect( 'dbi:AnyData' );
$dbh->func('mytable','XML',$file,$flags,'ad_catalog');
See below for a description of the optional flags that apply
to all of these examples.
=head1 DESCRIPTION
This module allows you to create, search, modify and/or convert XML data
and files by treating them as databases without having to actually
create separate database files. The data can
be accessed via a multidimensional tiedhash using AnyData.pm or via DBI
and SQL commands using DBD::AnyData.pm. See those modules for
complete details of usage.
The module is built on top of Michel Rodriguez's excellent XML::Twig which
means that the AnyData interfaces can now include information from DTDs,
be smarter about inferring data structure, reduce memory consumption on
huge files, and provide access to many powerful features of XML::Twig and
XML::Parser on which it is based.
Importing options allow you to import/access/modify XML of almost any length or complexity. This includes the ability to access different subtrees as separate or joined databases.
Exporting and converting options allow you to take data from almost any source (a perl array, any DBI database, etc.) and output it as an XML file. You can control the formatting of the resulting XML either by supplying a DTD listing things like nes...
The documentation below outlines the special flags that can be used
in either of the interfaces to fine-tune how the XML is treated.
The flags listed below define the relationship between tags and
attributes in the XML document and columns in the resulting database.
In many cases, you can simply accept the defaults and the database
will be built automatically. However, you can also fine tune the
generation of the database by specifying which tags and attributes
you are interested in and their relationship with database columns.
=head1 USAGE
=head2 Prerequisites
To use the tied hash interface, you will need
AnyData
XML::Twig
XML::Parser
To use the DBI/SQL interface, you will need those, and also
DBI
DBD::AnyData
=head2 Required flags ( none )
If no flags are specified, then the module determines the database
structure from examining the file or data itself, making use of the DTD if there is one, otherwise scanning the first child of the XML tree for structural information.
=head2 Optional flags
If the default behavior is not sufficient, you may either specify a
"record_tag" which will be used to define column names, or you can define an
entire tag-to-column mapping.
For simple XML, no flags are necessary:
<table>
<row row_id="1"><name>Joe</name><location>Seattle</location></row>
<row row_id="2"><name>Sue</name><location>Portland</location></row>
</table>
The record_tag will default to the first child, namely "row". The column
names will be generated from the attributes of the record tag and all of
the tags included under the record tag, so the column names in this
example will be "row_id","name","location".
If the record_tag is not the first child, you will need to specify it. For example:
<db>
<table table_id="1">
<row row_id="1"><name>Joe</name><location>Seattle</location></row>
<row row_id="2"><name>Sue</name><location>Portland</location></row>
</table>
<table table_id="2">
<row row_id="1"><name>Bob</name><location>Boise</location></row>
<row row_id="2"><name>Bev</name><location>Billings</location></row>
( run in 0.986 second using v1.01-cache-2.11-cpan-39bf76dae61 )