Обсуждение: XML -> PG ?

Поиск
Список
Период
Сортировка

XML -> PG ?

От
"Gauthier, Dave"
Дата:

Is there a way to read an XML file into a postgres DB?  I’m thinking that it will create and relate whatever tables are necessary to reflect whatever’s implied by the XML file structure.

 

Thanks for any pointers !

Re: XML -> PG ?

От
Merlin Moncure
Дата:
On Wed, May 6, 2009 at 10:47 AM, Gauthier, Dave <dave.gauthier@intel.com> wrote:
> Is there a way to read an XML file into a postgres DB?  I’m thinking that it
> will create and relate whatever tables are necessary to reflect whatever’s
> implied by the XML file structure.

since xml is basically completely unstructured, you are not giving
enough information about what you'd like to do. that said, be sure and
check out the pg xml extensions...

merlin

Re: XML -> PG ?

От
Christophe
Дата:

On May 6, 2009, at 10:47 AM, Gauthier, Dave wrote:

Is there a way to read an XML file into a postgres DB?  I’m thinking that it will create and relate whatever tables are necessary to reflect whatever’s implied by the XML file structure.

There's no built-in functionality that does what you describe, although building such a thing would be very straight-forward. There are many application-specific decisions you'd need to make (what level of hierarchy in the XML file corresponds to a database/schema/table, for example, and how to handle nested "fields" and missing ones).

Re: XML -> PG ?

От
"Gauthier, Dave"
Дата:
Maybe...

<ALL>
  <EMPLOYEES>
    <EMP EMP_NAME="JOE" JOB="CARPENTER" />
    EMP EMP_NAME="FRANK" JOB="PLUMBER"/>
    EMP EMP_NAME="SUE" JOB="CARPENTER"/>
  </EMPLOYEES>
  <JOBS>
    <JOB JOB_NAME="CARPENTER" SALARY=25.50 />
    <JOB JOB_NAME="PLUMBER" SALARY=28.75 />
  </JOBS>
</ALL>

...equals...

create table employees (emp_name varchar[64], job varchar[64]);
create table jobs (job_name varchar[64], salary float);
insert into employees (emp_name,job) values ('JOE','CARPENTER');
insert into employees (emp_name,job) values ('FRANK','PLUMBER');
insert into employees (emp_name,job) values ('SUE','CARPENTER');
insert into jobs (job_name,salary) values ("CARPENTER",25.50);
insert into jobs (job_name,salary) values ("PLUMBER",28.75);

After that, it's up to the user to understand that employees.job = jobs.job_name and index appropriately.





-----Original Message-----
From: Merlin Moncure [mailto:mmoncure@gmail.com]
Sent: Wednesday, May 06, 2009 11:23 AM
To: Gauthier, Dave
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] XML -> PG ?

On Wed, May 6, 2009 at 10:47 AM, Gauthier, Dave <dave.gauthier@intel.com> wrote:
> Is there a way to read an XML file into a postgres DB?  I'm thinking that it
> will create and relate whatever tables are necessary to reflect whatever's
> implied by the XML file structure.

since xml is basically completely unstructured, you are not giving
enough information about what you'd like to do. that said, be sure and
check out the pg xml extensions...

merlin

Re: XML -> PG ?

От
Joao Ferreira gmail
Дата:
hello,

as a perl addict I am... I recommend checking this out:

http://search.cpan.org/~cmungall/DBIx-DBStag/DBIx/DBStag/Cookbook.pm

it's pretty flexible and allows you to specify to some extent just how
the database structure is infered from the XML...

check it out

Joao




On Wed, 2009-05-06 at 11:31 -0400, Christophe wrote:
>
> On May 6, 2009, at 10:47 AM, Gauthier, Dave wrote:
>
> > Is there a way to read an XML file into a postgres DB?  I’m thinking
> > that it will create and relate whatever tables are necessary to
> > reflect whatever’s implied by the XML file structure.
>
>
> There's no built-in functionality that does what you describe,
> although building such a thing would be very straight-forward. There
> are many application-specific decisions you'd need to make (what level
> of hierarchy in the XML file corresponds to a database/schema/table,
> for example, and how to handle nested "fields" and missing ones).


Re: XML -> PG ?

От
Joao Ferreira gmail
Дата:
On Wed, 2009-05-06 at 16:53 +0100, Joao Ferreira gmail wrote:
> hello,
>
> as a perl addict I am... I recommend checking this out:
>
> http://search.cpan.org/~cmungall/DBIx-DBStag/DBIx/DBStag/Cookbook.pm
>
> it's pretty flexible and allows you to specify to some extent just how
> the database structure is infered from the XML...


... maybe start here to get a faster grasp:

http://search.cpan.org/~cmungall/DBIx-DBStag/DBIx/DBStag.pm

j


>
> check it out
>
> Joao
>
>
>
>
> On Wed, 2009-05-06 at 11:31 -0400, Christophe wrote:
> >
> > On May 6, 2009, at 10:47 AM, Gauthier, Dave wrote:
> >
> > > Is there a way to read an XML file into a postgres DB?  I’m thinking
> > > that it will create and relate whatever tables are necessary to
> > > reflect whatever’s implied by the XML file structure.
> >
> >
> > There's no built-in functionality that does what you describe,
> > although building such a thing would be very straight-forward. There
> > are many application-specific decisions you'd need to make (what level
> > of hierarchy in the XML file corresponds to a database/schema/table,
> > for example, and how to handle nested "fields" and missing ones).
>
>


Re: XML -> PG ?

От
Thomas Kellerer
Дата:
Gauthier, Dave, 06.05.2009 17:40:
> Maybe...
>
> <ALL>
>   <EMPLOYEES>
>     <EMP EMP_NAME="JOE" JOB="CARPENTER" />
>     EMP EMP_NAME="FRANK" JOB="PLUMBER"/>
>     EMP EMP_NAME="SUE" JOB="CARPENTER"/>
>   </EMPLOYEES>
>   <JOBS>
>     <JOB JOB_NAME="CARPENTER" SALARY=25.50 />
>     <JOB JOB_NAME="PLUMBER" SALARY=28.75 />
>   </JOBS>
> </ALL>
>
> ...equals...
>
> create table employees (emp_name varchar[64], job varchar[64]);
> create table jobs (job_name varchar[64], salary float);
> insert into employees (emp_name,job) values ('JOE','CARPENTER');
> insert into employees (emp_name,job) values ('FRANK','PLUMBER');
> insert into employees (emp_name,job) values ('SUE','CARPENTER');
> insert into jobs (job_name,salary) values ("CARPENTER",25.50);
> insert into jobs (job_name,salary) values ("PLUMBER",28.75);
>

You could use XSLT to tranform the XML into the approriate SQL Statements.

Thomas

Re: XML -> PG ?

От
Joao Ferreira
Дата:
On Wed, 2009-05-06 at 16:53 +0100, Joao Ferreira gmail wrote:
> hello,
>
> as a perl addict I am... I recommend checking this out:
>
> http://search.cpan.org/~cmungall/DBIx-DBStag/DBIx/DBStag/Cookbook.pm
>
> it's pretty flexible and allows you to specify to some extent just how
> the database structure is infered from the XML...
>

maybe start here to get a faster grasp:

http://search.cpan.org/~cmungall/DBIx-DBStag/DBIx/DBStag.pm

j


> check it out
>
> Joao
>
>
>
>
> On Wed, 2009-05-06 at 11:31 -0400, Christophe wrote:
> >
> > On May 6, 2009, at 10:47 AM, Gauthier, Dave wrote:
> >
> > > Is there a way to read an XML file into a postgres DB?  I’m thinking
> > > that it will create and relate whatever tables are necessary to
> > > reflect whatever’s implied by the XML file structure.
> >
> >
> > There's no built-in functionality that does what you describe,
> > although building such a thing would be very straight-forward. There
> > are many application-specific decisions you'd need to make (what level
> > of hierarchy in the XML file corresponds to a database/schema/table,
> > for example, and how to handle nested "fields" and missing ones).
>
>


Re: XML -> PG ?

От
Eric Schwarzenbach
Дата:
Gauthier, Dave wrote:
>
> Is there a way to read an XML file into a postgres DB?  I’m thinking
> that it will create and relate whatever tables are necessary to
> reflect whatever’s implied by the XML file structure.
>
>
>
> Thanks for any pointers !
>
That's a pretty common problem, and not one that needs to have a
postgresql-specific solution. There are definitely solutions out there,
but it may take some Googling to find a good one for your needs. One
option might be data binding tools (Castor and Liquid XML come to mind)
with which you can definitely go from XML to SQL, though many of them
may require going through an intermediate object model.

A simple approach (simple depending what technologies you're using and
are already familiar with) might be to use XSLT to transform your XML
either directly into SQL or into some other format easily loaded to a
database (such as the XML format used by DbUnit).

Eric

Re: XML -> PG ?

От
John R Pierce
Дата:
Gauthier, Dave wrote:
>
> Is there a way to read an XML file into a postgres DB? I’m thinking
> that it will create and relate whatever tables are necessary to
> reflect whatever’s implied by the XML file structure.
>
> Thanks for any pointers !
>

As others have said, the fundamental problem is that generalized XML is
freeform and inherently unstructured. Every piece of data can have a
different structure. IMHO, XML is fundamentally flawed by mixing the
metadata with the data.




Re: XML -> PG ?

От
Ries van Twisk
Дата:
On May 6, 2009, at 4:16 PM, Eric Schwarzenbach wrote:

> Gauthier, Dave wrote:
>>
>> Is there a way to read an XML file into a postgres DB?  I’m thinking
>> that it will create and relate whatever tables are necessary to
>> reflect whatever’s implied by the XML file structure.
>>
>>
>>
>> Thanks for any pointers !
>>
> That's a pretty common problem, and not one that needs to have a
> postgresql-specific solution. There are definitely solutions out
> there,
> but it may take some Googling to find a good one for your needs. One
> option might be data binding tools (Castor and Liquid XML come to
> mind)
> with which you can definitely go from XML to SQL, though many of them
> may require going through an intermediate object model.
>
> A simple approach (simple depending what technologies you're using and
> are already familiar with) might be to use XSLT to transform your XML
> either directly into SQL or into some other format easily loaded to a
> database (such as the XML format used by DbUnit).
>
> Eric


Call me a GUI boy, but I use JasperETL :)

Ries