From: | "Martin Drescher" <martin(dot)drescher(at)robotron(dot)de> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | BUG #4206: function xpath gives wrong results |
Date: | 2008-05-28 16:56:28 |
Message-ID: | 200805281656.m4SGuSE6059709@wwwmaster.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged online:
Bug reference: 4206
Logged by: Martin Drescher
Email address: martin(dot)drescher(at)robotron(dot)de
PostgreSQL version: 8.3.1
Operating system: Windows XP SP2
Description: function xpath gives wrong results
Details:
To demonstrate I use the following simple XML.
<?xml version="1.0"?>
<elem1>
<elem2>one</elem2>
<elem2>two</elem2>
<elem2>three</elem2>
<elem3 att="2"/>
</elem1>
I executed the following query in psql (with the corresponding XPath).
select xpath('//text()',xmlparse(document '<?xml version="1.0"
?><elem1><elem2>one</elem2><elem2>two</elem2><elem2>three</elem2><elem3
att="2"/></elem1>'));
The expected result is checked using Altova XMLSpy 2008.
XPath: (//text())[1]
Expected result: {one}
Actual Result:
ERROR: XX000: invalid XPath expression
DETAIL: Invalid expression
CONTEXT: SQL function "xpath" statement 1
LOCATION: xml_ereport, .\src\backend\utils\adt\xml.c:1351
XPath: boolean(/elem1)
Expected result: {true}
Actual Result:
ERROR: XX000: invalid XPath expression
DETAIL: Invalid expression
CONTEXT: SQL function "xpath" statement 1
LOCATION: xml_ereport, .\src\backend\utils\adt\xml.c:1351
XPath: /elem1/..
Expected result: document root
Actual Result:
{"<x>
<elem1>
<elem2>one</elem2>
<elem2>two</elem2>
<elem2>three</elem2>
<elem3 att=\"2\"/>
</elem1>
</x>"}
Note: This XPath returns the document root. I dont know, how you choose
to represent it. However, it should not return the element <x>
The problem imo is in .\src\backend\utils\adt\xml.c:3294, where a
<x>-element is wrapped around the xml and the XPath-expression is prepended
by "/x".
This is not needed for XML documents and fragments consisting of a single
root. Instead it breaks many XPath-Expressions; like where you use multiple
absolute path expressions or function calls.
I think, queries on a fragment consisting of multiple roots are not possible
with XPath 1.0.
From | Date | Subject | |
---|---|---|---|
Next Message | Gregory Stark | 2008-05-28 18:22:36 | Re: BUG #4204: COPY to table with FK has memory leak |
Previous Message | Bomken Basar | 2008-05-27 22:32:58 | BUG #4205: Unable to restore database |