Skip site navigation (1) Skip section navigation (2)

Re: xpath not a good replacement for xpath_string

From: Mike Rylander <mrylander(at)gmail(dot)com>
To: pgsql(at)mohawksoft(dot)com
Cc: PostgreSQL <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: xpath not a good replacement for xpath_string
Date: 2009-07-28 20:00:10
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Tue, Jul 28, 2009 at 3:21 PM, <pgsql(at)mohawksoft(dot)com> wrote:
> Sorry to bring this up, I know you've been fighting about XML for a while.
> Currently, I am using XML2 functionality and have tried to get the newer
> XPath function to work similarly, but can't quite seem to do it.
> I think the current xpath function is too limited. (The docs said to post
> problems to hackers if I have an issue.)
> For instance, we have a web application that uses java with an XML class
> serializer/deserializer Xstream. It creates XML that looks like this:
> <>
>    <uuid>b5212259-a91f-4dca-a547-4fe89cf2f32c</uuid>
>    <email>joe(at)somedomain(dot)com</email>
> </>
> My current strategy is to use xml2 as:
> select xpath_string(datum, E'/com\.company\.local\.myclass/uuid) as uuid
> from table;
> Which produces a usable:
> b5212259-a91f-4dca-a547-4fe89cf2f32c
> I have been trying to use xpath
> select xpath(E'/com\.company\.local\.myclass/uuid', XMLPARSE(CONTENT
> datum)) as uuid from table;
> Which produces an unusable:
> {<uuid>b5212259-a91f-4dca-a547-4fe89cf2f32c</uuid>}

How about:

SELECT (xpath(E'/com\.company\.local\.myclass/uuid/text()',
XMLPARSE(CONTENT datum)))[1] as uuid from table;

Not as clean, but it produces the same result as xpath_string().
Combined with array_to_string() could can collapse the array instead
of just grabbing the first element (in cases other than uuid, of

Mike Rylander
 | VP, Research and Design
 | Equinox Software, Inc. / The Evergreen Experts
 | phone:  1-877-OPEN-ILS (673-6457)
 | email:  miker(at)esilibrary(dot)com
 | web:

In response to

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2009-07-28 20:00:55
Subject: Re: xpath not a good replacement for xpath_string
Previous:From: Tom LaneDate: 2009-07-28 19:47:19
Subject: Re: WIP: Deferrable unique constraints

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group