1AnyData::Format::XML(3)User Contributed Perl DocumentatioAnnyData::Format::XML(3)
2
3
4

NAME

6        AnyData::Format::XML - tiedhash and DBI access to XML
7

SYNOPSIS

9        # access XML data via a multidimensional tied hash
10        # see AnyData.pod for full details
11        #
12        use AnyData;
13        my $table = adTie( 'XML', $file, $mode, $flags );
14
15        OR
16
17        # convert data to and from XML
18        # see AnyData.pod for full details
19        #
20        use AnyData;
21        adConvert( 'XML', $file1, $any_other_format, $file2, $flags );
22        adConvert( $any_other_format, $file1, 'XML', $file2, $flags );
23
24        OR
25
26        # access the data via DBI and SQL
27        # see DBD::AnyData.pod for full details
28        #
29        use DBI;
30        my $dbh = DBI->connect( 'dbi:AnyData' );
31        $dbh->func('mytable','XML',$file,$flags,'ad_catalog');
32
33       See below for a description of the optional flags that apply to all of
34       these examples.
35

DESCRIPTION

37       This module allows you to create, search, modify and/or convert XML
38       data and files by treating them as databases without having to actually
39       create separate database files.  The data can be accessed via a
40       multidimensional tiedhash using AnyData.pm or via DBI and SQL commands
41       using DBD::AnyData.pm.  See those modules for complete details of
42       usage.
43
44       The module is built on top of Michel Rodriguez's excellent XML::Twig
45       which means that the AnyData interfaces can now include information
46       from DTDs, be smarter about inferring data structure, reduce memory
47       consumption on huge files, and provide access to many powerful features
48       of XML::Twig and XML::Parser on which it is based.
49
50       Importing options allow you to import/access/modify XML of almost any
51       length or complexity.  This includes the ability to access different
52       subtrees as separate or joined databases.
53
54       Exporting and converting options allow you to take data from almost any
55       source (a perl array, any DBI database, etc.) and output it as an XML
56       file.  You can control the formatting of the resulting XML either by
57       supplying a DTD listing things like nesting of tags and which columns
58       should be output as attributes and/or you can use XML::Twig
59       pretty_print settings to generate half a dozen different levels of
60       compactness or whitespace in how the XML looks.
61
62       The documentation below outlines the special flags that can be used in
63       either of the interfaces to fine-tune how the XML is treated.
64
65       The flags listed below define the relationship between tags and
66       attributes in the XML document and columns in the resulting database.
67       In many cases, you can simply accept the defaults and the database will
68       be built automatically.  However, you can also fine tune the generation
69       of the database by specifying which tags and attributes you are
70       interested in and their relationship with database columns.
71

USAGE

73   Prerequisites
74       To use the tied hash interface, you will need
75
76        AnyData
77        XML::Twig
78        XML::Parser
79
80       To use the DBI/SQL interface, you will need those, and also
81
82        DBI
83        DBD::AnyData
84
85   Required flags ( none )
86       If no flags are specified, then the module determines the database
87       structure from examining the file or data itself, making use of the DTD
88       if there is one, otherwise scanning the first child of the XML tree for
89       structural information.
90
91   Optional flags
92        If the default behavior is not sufficient, you may either specify a
93        "record_tag" which will be used to define column names, or you can define an
94        entire tag-to-column mapping.
95
96       For simple XML, no flags are necessary:
97
98        <table>
99           <row row_id="1"><name>Joe</name><location>Seattle</location></row>
100           <row row_id="2"><name>Sue</name><location>Portland</location></row>
101        </table>
102
103       The record_tag will default to the first child, namely "row".  The
104       column names will be generated from the attributes of the record tag
105       and all of the tags included under the record tag, so the column names
106       in this example will be "row_id","name","location".
107
108       If the record_tag is not the first child, you will need to specify it.
109       For example:
110
111        <db>
112          <table table_id="1">
113            <row row_id="1"><name>Joe</name><location>Seattle</location></row>
114            <row row_id="2"><name>Sue</name><location>Portland</location></row>
115          </table>
116          <table table_id="2">
117            <row row_id="1"><name>Bob</name><location>Boise</location></row>
118            <row row_id="2"><name>Bev</name><location>Billings</location></row>
119          </table>
120        </db>
121
122       In this case you will need to specify "row" as the record_tag since it
123       is not the first child of the tree.  The column names will be generated
124       from the attributes of row's parent (if the parent is not the root),
125       from row's attributes and sub tags, i.e.
126       "table_id","row_id","name","location".
127
128       In some cases you will need to specify an entire tag-to-column mapping.
129       For example, if you want to use a different name for the database
130       column than is used in the XML (especially if the XML tag is not a
131       valid SQL column name).  You'd also need to specify a mapping if there
132       are two tags with the same name in different places in the XML tree.
133
134       The column mapping is a reference to an array of column definitions.  A
135       column definition is either a simple name of a tag, or a hash reference
136       with the key containing the full path of the XML tag and the value
137       containing the desired column name alias.
138
139       For example:
140
141         col_map => [ 'part_id', 'part_name', 'availability' ];
142
143       That will find the first three tags with those names and create the
144       database using the same names for the tags.
145
146       Or:
147
148         col_map => [
149                      { '/parts/shop/id'        => 'shop_id'},
150                      { '/parts/shop/part/id'   => 'part_id'},
151                      { '/parts/shop/part/name' => 'part_name'},
152                    ];
153
154       That would find the three tags referenced on the left and create a
155       database with the three column names referenced on the right.
156
157       When exporting XML, you can specify a DTD to control the output.  For
158       example, if you import a table from CSV or from an Array, you can
159       output as XML and specify which of the columns become tags and which
160       become attributes and also specify the nesting of the tags in your DTD.
161
162       The XML format parser is built on top of Michel Rodriguez's excellent
163       XML::Twig which is itself based on XML::Parser.  Parameters to either
164       of those modules may be passed in the flags for adTie() and the other
165       commands including the "prettyPrint" flag to specify how the output XML
166       is displayed and things like ProtocolEncoding.  ProtocolEncoding
167       defaults to 'ISO-8859-1', all other flags keep the defaults of
168       XML::Twig and XML::Parser.  See the documentation of those modules for
169       details;
170
171        CAUTION: Unlike other formats, the XML format does not save changes to
172        the file as they are entered, but only saves the changes when you explicitly
173        request them to be saved with the adExport() command.
174
176       copyright 2000, Jeff Zucker <jeff@vpservices.com> all rights reserved
177
178
179
180perl v5.36.0                      2023-01-19           AnyData::Format::XML(3)
Impressum