Re: BUG #4294: XML support: name() xpath function not working

Lists: pgsql-bugs
From: "Enrico Sirola" <enrico(dot)sirola(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4294: XML support: name() xpath function not working
Date: 2008-07-10 08:52:57
Message-ID: 200807100852.m6A8qvYM072317@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4294
Logged by: Enrico Sirola
Email address: enrico(dot)sirola(at)gmail(dot)com
PostgreSQL version: 8.3
Operating system: OSX, Linux (RHEL5)
Description: XML support: name() xpath function not working
Details:

it seems the name() xpath function doesn't work properly. Try, for example,
the following sql script:

create table test (test xml);
insert into test values ('<a
xmlns="http://myns.com/ns"><b>text1</b><c>text2</c></a>');
-- good
select xpath('/my:a/*[last()]', test, ARRAY[ARRAY['my',
'http://myns.com/ns']]) from test;
-- bad
select xpath('name(/my:a/*[last()])', test, ARRAY[ARRAY['my',
'http://myns.com/ns']]) from test;

It seems the libxml2 version and the OS used is not relevant. The problem
affects all pgsql versions >= 8.3.0

Best regards,
Enrico


From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4294: XML support: name() xpath function not working
Date: 2008-07-10 16:57:36
Message-ID: 1215709056.4051.1381.camel@ebony.2ndQuadrant
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


On Thu, 2008-07-10 at 08:52 +0000, Enrico Sirola wrote:

> create table test (test xml);
> insert into test values ('<a
> xmlns="http://myns.com/ns"><b>text1</b><c>text2</c></a>');
> -- good
> select xpath('/my:a/*[last()]', test, ARRAY[ARRAY['my',
> 'http://myns.com/ns']]) from test;
> -- bad
> select xpath('name(/my:a/*[last()])', test, ARRAY[ARRAY['my',
> 'http://myns.com/ns']]) from test;

What error messages are you getting?

Why do you think this should work? Best post a test case using another
tool, or a URL to an example.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Enrico Sirola" <enrico(dot)sirola(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #4294: XML support: name() xpath function not working
Date: 2008-07-11 04:28:14
Message-ID: 24419.1215750494@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Enrico Sirola" <enrico(dot)sirola(at)gmail(dot)com> writes:
> -- bad
> select xpath('name(/my:a/*[last()])', test, ARRAY[ARRAY['my',
> 'http://myns.com/ns']]) from test;

You could barely swat a fly with what I know about XPath ... but I'm
thinking that the culprit here is the crock at lines 3254-3288 of
xml.c, which explains itself thus:

/*
* To handle both documents and fragments, regardless of the fact whether
* the XML datum has a single root (XML well-formedness), we wrap the XML
* datum in a dummy element (<x>...</x>) and extend the XPath expression
* accordingly. To do it, throw away the XML prolog, if any.
*/

This code prefixes the given path expression with "/x", which of course
is going to break any expression that starts with a function name. It
would have to stick the /x inside the function argument to have any
chance of working. In general, I think this has zero chance of working
without implementing a pretty complete XPath parser. We need to find
another way.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #4294: XML support: name() xpath function not working
Date: 2008-08-23 03:22:09
Message-ID: 200808230322.m7N3M9w06962@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


Is there any TODO here?

---------------------------------------------------------------------------

Tom Lane wrote:
> "Enrico Sirola" <enrico(dot)sirola(at)gmail(dot)com> writes:
> > -- bad
> > select xpath('name(/my:a/*[last()])', test, ARRAY[ARRAY['my',
> > 'http://myns.com/ns']]) from test;
>
> You could barely swat a fly with what I know about XPath ... but I'm
> thinking that the culprit here is the crock at lines 3254-3288 of
> xml.c, which explains itself thus:
>
> /*
> * To handle both documents and fragments, regardless of the fact whether
> * the XML datum has a single root (XML well-formedness), we wrap the XML
> * datum in a dummy element (<x>...</x>) and extend the XPath expression
> * accordingly. To do it, throw away the XML prolog, if any.
> */
>
> This code prefixes the given path expression with "/x", which of course
> is going to break any expression that starts with a function name. It
> would have to stick the /x inside the function argument to have any
> chance of working. In general, I think this has zero chance of working
> without implementing a pretty complete XPath parser. We need to find
> another way.
>
> regards, tom lane
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #4294: XML support: name() xpath function not working
Date: 2008-08-23 03:25:15
Message-ID: 23616.1219461915@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Is there any TODO here?

It's clearly broken, if that's what you mean. I don't know enough XPath
to speculate about an appropriate fix.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #4294: XML support: name() xpath function not working
Date: 2008-08-23 03:35:00
Message-ID: 200808230335.m7N3Z0b15574@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Is there any TODO here?
>
> It's clearly broken, if that's what you mean. I don't know enough XPath
> to speculate about an appropriate fix.

The XML wiki already had bug reports about <x> so I added this report to
that list.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +