.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "AnyData::Format::XML 3pm" .TH AnyData::Format::XML 3pm "2012-09-07" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" .Vb 1 \& AnyData::Format::XML \- tiedhash and DBI access to XML .Ve .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& # access XML data via a multidimensional tied hash \& # see AnyData.pod for full details \& # \& use AnyData; \& my $table = adTie( \*(AqXML\*(Aq, $file, $mode, $flags ); \& \& OR \& \& # convert data to and from XML \& # see AnyData.pod for full details \& # \& use AnyData; \& adConvert( \*(AqXML\*(Aq, $file1, $any_other_format, $file2, $flags ); \& adConvert( $any_other_format, $file1, \*(AqXML\*(Aq, $file2, $flags ); \& \& OR \& \& # access the data via DBI and SQL \& # see DBD::AnyData.pod for full details \& # \& use DBI; \& my $dbh = DBI\->connect( \*(Aqdbi:AnyData\*(Aq ); \& $dbh\->func(\*(Aqmytable\*(Aq,\*(AqXML\*(Aq,$file,$flags,\*(Aqad_catalog\*(Aq); .Ve .PP See below for a description of the optional flags that apply to all of these examples. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module allows you to create, search, modify and/or convert \s-1XML\s0 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 \s-1DBI\s0 and \s-1SQL\s0 commands using DBD::AnyData.pm. See those modules for complete details of usage. .PP 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. .PP Importing options allow you to import/access/modify \s-1XML\s0 of almost any length or complexity. This includes the ability to access different subtrees as separate or joined databases. .PP Exporting and converting options allow you to take data from almost any source (a perl array, any \s-1DBI\s0 database, etc.) and output it as an \s-1XML\s0 file. You can control the formatting of the resulting \s-1XML\s0 either by supplying a \s-1DTD\s0 listing things like nesting of tags and which columns should be output as attributes and/or you can use XML::Twig pretty_print settings to generate half a dozen different levels of compactness or whitespace in how the \s-1XML\s0 looks. .PP The documentation below outlines the special flags that can be used in either of the interfaces to fine-tune how the \s-1XML\s0 is treated. .PP The flags listed below define the relationship between tags and attributes in the \s-1XML\s0 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. .SH "USAGE" .IX Header "USAGE" .SS "Prerequisites" .IX Subsection "Prerequisites" To use the tied hash interface, you will need .PP .Vb 3 \& AnyData \& XML::Twig \& XML::Parser .Ve .PP To use the \s-1DBI/SQL\s0 interface, you will need those, and also .PP .Vb 2 \& DBI \& DBD::AnyData .Ve .SS "Required flags ( none )" .IX Subsection "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 \s-1DTD\s0 if there is one, otherwise scanning the first child of the \s-1XML\s0 tree for structural information. .SS "Optional flags" .IX Subsection "Optional flags" .Vb 3 \& 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. .Ve .PP For simple \s-1XML\s0, no flags are necessary: .PP .Vb 4 \& \& JoeSeattle \& SuePortland \&
.Ve .PP The record_tag will default to the first child, namely \*(L"row\*(R". 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 \*(L"row_id\*(R",\*(L"name\*(R",\*(L"location\*(R". .PP If the record_tag is not the first child, you will need to specify it. For example: .PP .Vb 10 \& \& \& JoeSeattle \& SuePortland \&
\& \& BobBoise \& BevBillings \&
\&
.Ve .PP In this case you will need to specify \*(L"row\*(R" as the record_tag since it is not the first child of the tree. The column names will be generated from the attributes of row's parent (if the parent is not the root), from row's attributes and sub tags, i.e. \*(L"table_id\*(R",\*(L"row_id\*(R",\*(L"name\*(R",\*(L"location\*(R". .PP In some cases you will need to specify an entire tag-to-column mapping. For example, if you want to use a different name for the database column than is used in the \s-1XML\s0 (especially if the \s-1XML\s0 tag is not a valid \s-1SQL\s0 column name). You'd also need to specify a mapping if there are two tags with the same name in different places in the \s-1XML\s0 tree. .PP The column mapping is a reference to an array of column definitions. A column definition is either a simple name of a tag, or a hash reference with the key containing the full path of the \s-1XML\s0 tag and the value containing the desired column name alias. .PP For example: .PP .Vb 1 \& col_map => [ \*(Aqpart_id\*(Aq, \*(Aqpart_name\*(Aq, \*(Aqavailability\*(Aq ]; .Ve .PP That will find the first three tags with those names and create the database using the same names for the tags. .PP Or: .PP .Vb 5 \& col_map => [ \& { \*(Aq/parts/shop/id\*(Aq => \*(Aqshop_id\*(Aq}, \& { \*(Aq/parts/shop/part/id\*(Aq => \*(Aqpart_id\*(Aq}, \& { \*(Aq/parts/shop/part/name\*(Aq => \*(Aqpart_name\*(Aq}, \& ]; .Ve .PP That would find the three tags referenced on the left and create a database with the three column names referenced on the right. .PP When exporting \s-1XML\s0, you can specify a \s-1DTD\s0 to control the output. For example, if you import a table from \s-1CSV\s0 or from an Array, you can output as \s-1XML\s0 and specify which of the columns become tags and which become attributes and also specify the nesting of the tags in your \s-1DTD\s0. .PP The \s-1XML\s0 format parser is built on top of Michel Rodriguez's excellent XML::Twig which is itself based on XML::Parser. Parameters to either of those modules may be passed in the flags for \fIadTie()\fR and the other commands including the \*(L"prettyPrint\*(R" flag to specify how the output \s-1XML\s0 is displayed and things like ProtocolEncoding. ProtocolEncoding defaults to '\s-1ISO\-8859\-1\s0', all other flags keep the defaults of XML::Twig and XML::Parser. See the documentation of those modules for details; .PP .Vb 3 \& CAUTION: Unlike other formats, the XML format does not save changes to \& the file as they are entered, but only saves the changes when you explicitly \& request them to be saved with the adExport() command. .Ve .SH "AUTHOR & COPYRIGHT" .IX Header "AUTHOR & COPYRIGHT" copyright 2000, Jeff Zucker all rights reserved