Re: DBIx::XML::DataLoader



On 2008-04-15 02:10, Ted <r.ted.byers@xxxxxxxxxx> wrote:
I am trying to figure out how to use this package. It looks like it
may do what I need, and help me write the code more quickly than would
be the case if I started de novo.

First, although I have been programming in a variety of languages for
quite a while, i have managed to avoid having to parse XML until now.
I HATE parsing. I'd rather be implementing a new numeric integration
algorithm or method for some obscure but interesting statistical
analysis. But here I am and have to get this done.

The data feed I get appears to be well formed XML, but it is open
ended in that there is no defined schema. The only information I have
about what to expect in the XML is provided in the data feed
provider's documentation. The data structure appears to be very
simple, but working with it is tedious at best.

Is there a package or utility that can read an XML file of the sort I
get and create a schema based on what it sees in the data feed file?

In the page for DBIx::XML::DataLoader::MapIt, I see the following:

<XMLtoDB>
<RootElement name="/Users"/>
<dbinfo dbuser="user" dbpass="pass"
dbsource="dbi:mysql:userdata" name="userdata"/>
<Table name="userinfo" dbname="userdata" xpath="./
user">
<KeyColumn name="USER_ID" order="1"/>
<KeyColumn name="USER_LAST_NAME" order="2"/>
<KeyColumn name="USER_FIRST_NAME" order="3"/>
<Element xpath="./id" toColumn="USER_ID"/>
<Element xpath="./last_name"
toColumn="USER_LAST_NAME"/>
<Element xpath="./first_name"
toColumn="USER_FIRST_NAME"/>
<Element xpath="./phone_number"
toColumn="PHONE_NUMBER"/>
</Table>
</XMLtoDB>};

Please bear with me for a moment. Am I to understand this is a
typical example of what a map file looks like? If I understand this
example correctly, the root element is just the outer most element of
the XML file to be expected. The dbinfo specifies the login
credentials to the database, and the database. It isn't clear to me
though what the name tag is for. Isn't the database specified as the
last item in the dbsource element? If so, of what value is the name
element?

I think (just from superficially reading
http://search.cpan.org/~cberning/DBIx-XML-DataLoader-1.1b/DataLoader.pm,
I've never used this module) that you can use it to specify multiple
databases in the same map file. Then you can say "this data goes into
table X on database A, and this goes into table Y on database B". If you
don't need that, just choose a descriptive name.

I would assume, based on what I see, that this package can
readily connect to a database implemented within MySQL.

The table element is of most interest. Obviously, I can create a
suite of tables that correspond to the structure of the XML file.
Also obviously not all columns in the database are keys or indeces.
And, I have no idea what XPATH is, let alone what to do with it.

XPath is like Perl. It gets cranky when it's spelt in all upper case
;-).

Seriously: XPath is a language for selecting stuff from an XML file.
Sort of what regexps are for plain text or SQL for relational databases.
You can find the specification at http://www.w3.org/TR/xpath20/ and
google will help you find tutorials (Sorry, I don't have a good one at
hand - you'll probably have to read several of them and the specs, too
to get the hang of it).


would hazard a guess that the KeyColumn and Element items map elements
in the XML file to elements in the table in the database.

Seems plausible.

But it
isn't clear what I should do with columns that are NOT keys,

Just use an Element without a KeyColumn. Note that the Element element
has two attributes: xpath (which specifies where to find the data in
the XML file) and toColumn (which specifies where to put the data in the
table).

or what to do when the XML file is hierarchical, with nested elements
that logically ought to be placed in a different table, and keys
created to link the tables together (for example, imagine a trivial
address book that supports peole having multiple addresses, multiple
email addresses, and multiple phone numbers - or they may well NOT
have a phone or email).

If the XML file already contains the keys, you can specify them with
xpath. If it doesn't you are probably supposed to create them in a
handler.

hp
.



Relevant Pages

  • Re: DBIx::XML::DataLoader
    ... of tables that correspond to the structure of the XML file. ... obviously not all columns in the database are keys or indeces. ... have no idea what XPATH is, let alone what to do with it. ...
    (comp.lang.perl.misc)
  • Re: DBIx::XML::DataLoader
    ... obviously not all columns in the database are keys or indeces. ... XPath is like Perl. ... XPath is a language for selecting stuff from an XML file. ... May I advice the OP to get the O'Reilly XML book? ...
    (comp.lang.perl.misc)
  • Re: Multiple DB Maintenance Creation?
    ... You should look up "SQLMAINT", which has a command line option for recurring ... Use sqlmaint to run DBCC checks, back up a database ... Specifies the target instance of Microsoft® SQL ServerT 2000. ... Specifies a backup action. ...
    (microsoft.public.sqlserver.server)
  • Re: XML parser and writer
    ... XStream, Castor, JAXB come to mind. ... why not some database technology? ... an advanced user can edit the XML file directly at ...
    (comp.lang.java.programmer)
  • Re: XML parser and writer
    ... them on a calendar. ... set for it and I was thinking of storing all the data in an XML file. ... why not some database technology? ... Tasklist the DOM would quickly become unwieldy especially if you have any ...
    (comp.lang.java.programmer)