Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

mapping between XML & DB Schemas

by zuqif (Hermit)
on Jun 16, 2008 at 15:35 UTC ( [id://692282]=perlquestion: print w/replies, xml ) Need Help??

zuqif has asked for the wisdom of the Perl Monks concerning the following question:

Enlightened Monks, from the wonderful world of perl.

Humbly, please put me out my misery with the pertinent cluebat.

I have to deliver several (largish) XML documents in accordance with their XSD.
These schema are subject to frequent & outwith-my-control changes.
The 'contents' for the XML live in MySQL, in what might kindly be termed an 'evolved' table/relationship.

surely, surely, surely someone somewhere has had to deliver XML from SQL in a controlled, extensible manner previously?

There are many excellent CPAN entries which could handle parts of my requirement, but I've yet to find anythign which lets me markup the relationships between allowable XML schema elements, & their database residence.

Currently we do a number of SELECTs, munge & call XML-Writer, which works but is harder to maintain.

I have a window of opportunity to do-it-right & would humbly petition for your gems of wisdom ..

thanks in advance

the 'qif;

Replies are listed 'Best First'.
Re: mapping between XML & DB Schemas
by mirod (Canon) on Jun 16, 2008 at 15:41 UTC

    At this point, it looks like the best solution to use XSD with Perl is XML::Compile, have a look at it.

      Excellent - a perfect starter in the right direction - I can build my mapping data on top of the parsed schema structure.

      Am beginning to fear that encapsulating the necessary XSD->SQL mapping data & handlers required is more effort than can be justified here .. better do some proof-of-concept for $phb!

      cheers for the pointer ;)

      the 'qif;
Re: mapping between XML & DB Schemas
by radiantmatrix (Parson) on Jun 16, 2008 at 20:52 UTC

    The mysql command can be used to generate XML of a query -- you could also use something like XML::Simple to easily dump the result of a query; you can then use XSLT (if you want, there are modules for that) to transform that XML output into XML compliant with your XSD.

    XML transformation via XSLT is the "right way" to do it, if we mean by "right way": "in accordance with the standards documents and theory". There are other definitions. ;-)

    For example, you might check out XML::Generator::DBI, which generates SAX events (which you can handle to with XML::SAX::Writer, for example) from DBI queries.

    Based on some guesses from your description, you might also consider XML::Template for writing, and the XML::Template::DBI to serve as a data source for your template.

    <radiant.matrix>
    Ramblings and references
    “A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort.” — Herm Albright
    I haven't found a problem yet that can't be solved by a well-placed trebuchet
      all excellent pointers!

      apologies for not being more specific, but am less concerned with *how* to get & export the data -
      am really looking for advice on building some sort of data-dictionary mapping between XML and the DB
      which can be used to auto-build the get/export routines, however they may end up implemented.

      It seems like a sensible shortcut to me, but if no-one has already done similar, I must have overlooked a glaring flaw?!

      the 'qif;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://692282]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found