pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Russ Tennant <russ@i2rd.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: XML document with doctype
Date: Thu, 24 Jan 2013 12:37:12 -0600
Message-ID: <51017F58.7070804@i2rd.com> (raw)
In-Reply-To: <CADK3HHKV94m3tfhAy0cxYeruEUZs4Wv=VWKrFw=_Aow1JwLpbg@mail.gmail.com>
References: <51008284.3080202@i2rd.com>
	<CADK3HHKV94m3tfhAy0cxYeruEUZs4Wv=VWKrFw=_Aow1JwLpbg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Dave,

Thanks for the response. I had reviewed the source code for the version
9.0 driver, org.postgresql.jdbc4.Jdbc4SQLXML &
org.postgresql.jdbc4.AbstractJdbc4Statement.setSQLXML(int, SQLXML),  and
I had already implemented hibernate code, XMLUserType, to add support
for SQLXML for the version of hibernate we use. It works great except
when we try to store something like "<!DOCTYPE foo><foo/>". The issue
I'm having is providing a way to pass along information (JDBC- >
PostgreSQL) on whether the XML string passed via SQLXML is a
DOCUMENT/CONTENT (
http://www.postgresql.org/docs/9.0/static/datatype-xml.html ) so that it
is converted correctly when it hits the server. I was wondering if there
is a way to do this other than what I mentioned previously.

Basically, I'm trying to find the best method to pass DOCUMENT/CONTENT
info through Hibernate -> JDBC -> PostgreSQL. I am not seeing any way to
do it with SQLXML. I wanted to make sure I wasn't missing some easier
way of doing this before writing custom Hibernate code to generate the
needed SQL.

Example of what I mean by CONTENT vs DOCUMENT:

Default of CONTENT:

    (russ@[local]:5432) [russ] > INSERT INTO foo VALUES('<!DOCTYPE
    foo><foo/>');
    ERROR:  invalid XML content
    LINE 1: INSERT INTO foo VALUES('<!DOCTYPE foo><foo/>');
                                   ^
    DETAIL:  Entity: line 1: parser error : StartTag: invalid element name
    <!DOCTYPE foo><foo/>
     ^


Specifying DOCUMENT:

    (russ@[local]:5432) [russ] > INSERT INTO foo
    VALUES(XMLPARSE(DOCUMENT '<!DOCTYPE foo><foo/>'));
    INSERT 0 1
    Time: 0.455 ms



On 1/24/2013 2:20 AM, Dave Cramer wrote:
> Russ,
>
> A cursory glance at JDBC4 suggests that there is support for the
> SQLXML type in the driver. Does hibernate have any support for it.
>
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Wed, Jan 23, 2013 at 7:38 PM, Russ Tennant <russ@i2rd.com
> <mailto:russ@i2rd.com>> wrote:
>
>     Is there a way to persist XML data as a DOCUMENT as opposed to CONTENT
>     (the default) without using SET XML OPTION / XMLPARSE?
>
>     I'm using Hibernate and don't have control over building of the
>     SQL for
>     the PreparedStatement out of the box or when it executes to wrap calls
>     to SET XML OPTION. For Hibernate, I'm using a UserType I wrote
>     that uses
>     SQLXML. In my case, I usually have XML content so it works fine in
>     those
>     cases; occasionally, I have a document to persist and then it will
>     fail
>     occasionally unless I tell PG that it is a document. I'm trying to
>     find
>     the best way to work with Hibernate when I have a document while
>     minimizing the amount of Hibernate code I have to write. Before I
>     delve
>     into that, I wanted to make sure I wasn't missing any other
>     options for
>     passing along DOCUMENT/CONTENT info for converting from a string to an
>     XML type.
>
>     So, it looks like my options are: XMLPARSE (custom SQL) and SET XML
>     OPTION. Are there any other options that I'm missing? Thanks for
>     any help.
>

-- 
Russ Tennant
Software Engineer
I2RD (Interactive Information R&D)
Email: russ@i2rd.com

view thread (3+ messages)

Message-ID: <51017F58.7070804@i2rd.com>
Permalink:  ../51017F58.7070804@i2rd.com/
Also on:    postgresql.org/message-id/51017F58.7070804@i2rd.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: russ@i2rd.com
  Subject: Re: XML document with doctype
  In-Reply-To: <51017F58.7070804@i2rd.com>
  References: <51008284.3080202@i2rd.com> <CADK3HHKV94m3tfhAy0cxYeruEUZs4Wv=VWKrFw=_Aow1JwLpbg@mail.gmail.com> <51017F58.7070804@i2rd.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox