Pedro,

This sounds like an interesting project.

First let me try to repeat back what you have told me, so as to make
sure that I understand you correctly.

1. You have a set of (42) XML schemas.

2. You want to be able to make queries to a relational database.

3. You want to convert the results of a query (or set of queries)
   into a XML instance document that is an instance of one of your
   42 XML schemas.

4. You want to do this in Python.

If the above are correct, here are some suggestions and comments:

- I suspect that you have already found it, but if not, be sure to
  look at Lxml (http://lxml.de/).  For Python, it is our strongest
  (although somewhat low level) XML library.  You can also consider
  using ElementTree, which is in the Python standard library and
  which implements a subset of the capabilites of Lxml.
  
- You might consider looking at each of your XML schemas (those XSD
  files you mention), and writing a python module for each XML
  schema and in that Python module you might implement a class for
  each xsd:complexType in that XML schema.

- In that class there would be a constructor (def __init__(self, ...))
  and an export/write method.  The export method would write out a
  piece of an XML file.  Effectively, it would write out the XML for
  the element corresponding to that xsd:complexType.

- There is an existing product which possibly does this
  automatically, that is, you give it an XML schema and it generates
  a Python module that contains those classes, one class for each
  xsd:complexType in the schema.  However, I hesitate to mention
  this project, for two reasons: (1) because I am the one who
  implemented and maintains it, so I am very biased about it; and
  (2) although it attempts to handle all XML schemas, even complex
  ones, there are some that give it problems.

  The name of this project is generateDS.py, and it is located here:
  https://bitbucket.org/dkuhlman/generateds

  Take a look.  Perhaps it solves your problem, perhaps not.  But,
  even if it does not, looking at the code it generates (which uses
  Lxml) may give you ideas about how to proceed in other ways.

By the way, I am assuming that your SQL queries will use joins on
relational database tables that have foreign keys (or something like
that; I am not a relational database expert).  If so, you will
likely want to generate XML documents that contain elements which
contain elements which contain nested elements ...  generateDS.py
attempts to handle that nesting for you, so the code it generates
may be a good model either for writing your own code by hand or
that generated code may even do what you need.

I Hope this helps.  Let me know if and when you have more specific
questions.

Dave

On Fri, Oct 06, 2017 at 07:19:25PM +0000, PEDRO HENRIQUE RAMOS RIBEIRO wrote:
>    Hello, David.
>    I work for a state software company in Brazil. 
>    I am a software developer with many yeras in Python but none in XML. So I
>    write you asking for some guidance.
>    I am in charge of this new project that has to periodically extract 42
>    diferents sets of data from an Oracle database and generate XML files.
>    Each set of data has a respective XSD.
>    My idea is to create an extractor that has two inputs: a transformation
>    mapping and a XSD. And that would read the result of a SQL query and
>    generate the XML.
>    Does that makes sense for you? If yes, what strategy would you use and
>    which set of libraries (because there are so many) would you direct me
>    for?
>    Thank you so much in advance,
>    Pedro Ribeiro  
>    --
>     
> 
>    Pedro Ribeiro
>    Gestor de Projetos
>    EGP/GPROS
>    Vice-Presidência de Tecnologia
>    Telefones: (48) 3664-1034 / (48) 9616-4812
>    E-mail: phrribe...@ciasc.sc.gov.br
> 
>    Centro de Informática e Automação do Estado de Santa Catarina S.A.
>    Centro de Apoio CIASC: (48) 3664-1100
>    www.ciasc.sc.gov.br

-- 

Dave Kuhlman
http://www.davekuhlman.org

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to