views:

22

answers:

1

I am writing a software package whose job is to export DB data from my company's main product into arbitrary XML formats (for interfacing with other applications.) Parsing of arbitrary XML datafiles into our database may be next. I am writing in C/C++, and the product's database is stored as Pervasive BTRV files in a proprietary format.

I need to write a mapping format that can map our internal data elements to XML, so that if my export package is given a mapping file it will create the desired XML output file from the contents of the database. What strategies or tools would you recommend I use to accomplish this?

Some options I have considered:

  1. Devise a common XML export schema for the product, and then write XSLT files to convert this format into arbitrary XML files.
  2. Write an XSD Schema file that defines the structure of the output file, and design a set of processing instructions that tell my package which data items go in which elements.

I consider myself to be a novice at using XML; I am familiar with XSLT and XPath, and starting to learn Schema, but there may be obvious tools to solve this problem that I am missing.

(Update, 8:14p PDT: The package I am writing is designed to hook into our generic external-interfacing module, for use in exporting data that will be consumed by other applications. Under standard use, when a subset of the database changes or is "finalized", that subset will be automatically exported in a format the other application can understand. I am attempting to extend the external-interfacing module to give it the ability to output these "finalized" data items in XML.

My job is to define a method of specifying the XML format the other system expects. Since the target schema could vary widely between applications, I need a solution that can handle a range of possible XML schema; I also need a solution that is easy to configure/maintain for each interface.

The code that will be calling my code treats the database items as a series of nested containers, and provides hooks for formatting each nested layer. Those hooks seem very similar to the match attribute on <xsl:template>, which is what led me to consider XSLT as a possible solution.)

A: 

I would recommend outputting your database to an XML file and use XSLT to transform it to any XML format the other party requires, using different XSLT stylesheets for each transformation. That way, you will only have to change your XSLT files to interface various applications.

If you are using a schema-aware processor or a tool like Altova XMLSpy, I recommend you create a schema for your database's XML file. It saves you lots of hair. If the XML of the other party is complex, I would create a schema for that as well.

The advantages of schemas, besides of validating your files and better understanding the structure, are that a tool like XMLSpy will automatically help you with fields, assist you with XPath and so on. Besides, a tool like MapForce even creates the XSLT for you if you provide it with two schemas (haven't tried).

PeerBr