Re: Postgresql 8.4, XPath and name() function

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: ced45 <cedric(dot)duprez(at)ifn(dot)fr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Postgresql 8.4, XPath and name() function
Date: 2010-07-14 17:30:16
Message-ID: AANLkTiktGlmIivdLyYltUwPjMquz7VLgwKoovviBNR2o@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 13, 2010 at 4:03 AM, ced45 <cedric(dot)duprez(at)ifn(dot)fr> wrote:
>
> Hi List,
>
> I have trouble using XPath name() function in a XML field.
> For example, when I execute the following query :
>
> SELECT XPATH('name(/*)', XMLPARSE(DOCUMENT '<unit>value</unit>'))
>
> I would like to get "unit", but I just get an empty array ({}).
> How can I get "unit" ?

postgres is slightly broken in this regard. here is some discussions
and a (might not work anymore) patch to fix the behavior if you're
feeling adventurous...

http://www.mail-archive.com/pgsql-hackers(at)postgresql(dot)org/msg143339.html

here is a 'works for my cases but probably not all of yours' regex
solution that I use sometimes:
create or replace function xnode(_xml xml) returns text as
$$
select substring($1::text from '^<([[:alnum:]]+).*>');
$$ language sql immutable;

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2010-07-14 18:06:15 Re: Any ideas on Version 9.0 production release date?
Previous Message Darin Del Vecchio 2010-07-14 17:05:59 Any ideas on Version 9.0 production release date?