Transform mapped XPath expressions into XML containing relational data - Mailing list pgsql-hackers

From Thangalin
Subject Transform mapped XPath expressions into XML containing relational data
Date
Msg-id CAANrE7r=81tCGsr_bNQrotvREiNSD5idk8NarxM4cB8jwnHuMQ@mail.gmail.com
Whole thread Raw
Responses Re: Transform mapped XPath expressions into XML containing relational data  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Hi,

Is it possible to build an XML (or JSON) document using a map database columns to XPath expressions? For example:

root               > people
person             > person
person.first_name -> name/first
person.last_name  -> name/last
person.age        -> [@age]
account.person_id => person.person_id
account            > person/account
account.number    -> [@id]

The arrows have meanings (RHS = right-hand side; LHS = left-hand side):

  • > ... Container element (no text values); RHS is the element name.
  • -> ... Path to a text value; RHS is the XPath to the element name.
  • => ... Join expression; RHS references the attribute in a previously listed LHS table name.

PERSON table might resemble:

person_id | first_name | last_name | age      123 | Peter      | Parker    | 18      456 | James      | Jameson   | 42

And an ACCOUNT table might resemble:

account_id | person_id | number         1 |       123 | 123456789

Querying the database using the XPath map would produce the following XML document:

<people>  <person age="18">    <name>      <first>Peter</first>      <last>Parker</last>    </name>    <account id="123456789" />  </person>  <person age="42">    <name>      <first>James</first>      <last>Jameson</last>    </name>  </person>
</people>

In this case, James Jameson does not have an account and so the corresponding XML element (account) is not included in the final document.

This would make it trivial to generate a JSON document without changing the underlying code; whereas, hand-coding the XML document with combinations of the xml* functions semantically prohibits a direct transmogrification of the output format.

Thoughts?

pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: 64 bit ints vs libpq-fe.h
Next
From: Robert Haas
Date:
Subject: Re: WIP json generation enhancements