(unnamed)
text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Robert Haas wrote:
<blockquote
cite="mid:603c8f071001051854x10875b50vf620a3fca727ab11@mail.gmail.com"
type="cite">
<pre wrap="">On Tue, Jan 5, 2010 at 6:09 PM, Arie Bikker <a
class="moz-txt-link-rfc2396E" href="mailto:arie@abikker.nl"><arie@abikker.nl></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,
Well I had to burn some midnight oil trying to figure out why a construct
like
SELECT xpath('name()','<a/>');
doesn't give the expected result. Kept getting an empty array:
xpath
-------------
{}
instead of the expected "{a}"
BugID 4294 and the TODO item "better handling of XPath data types" pointed
in the right direction.
whithin src/backend/utils/adt/xml.c in the function xpath the result of the
call to xmlXPathCompiledEval is not handled optimally. In fact, the result
is assumed to be a nodeset without consulting the ->type member of the
result. I've made some minor changes to xml.c to handle some non-nodeset
results of xmlXPathCompiledEval.
Essentially, the revised code makes an array of all the nodes in the
xpathobj result in case this is a nodeset, or an array with a single element
in case the reult is a number/string/boolean. The problem cases mentioned in
<a class="moz-txt-link-freetext"
href="http://archives.postgresql.org/pgsql-hackers/2008-06/msg00616.php">http://archives.postgresql.org/pgsql-hackers/2008-06/msg00616.php</a> now work
as expected.
Revision of the code involves:
- A switch statement to handle the result type of xmlXPathCompiledEval.
- an additional function xmlpathobjtoxmltype.
diff of the revisioned code with respect to original is in attached file.
kind regards, Arie Bikker
</pre>
</blockquote>
<pre wrap=""><!---->
Hi,
Could you please resend this as a context diff and add it to our patch
management application?
<a class="moz-txt-link-freetext"
href="http://wiki.postgresql.org/wiki/Submitting_a_Patch">http://wiki.postgresql.org/wiki/Submitting_a_Patch</a>
<a class="moz-txt-link-freetext"
href="https://commitfest.postgresql.org/action/commitfest_view/open">https://commitfest.postgresql.org/action/commitfest_view/open</a>
Thanks!
...Robert
</pre>
</blockquote>
Hope this is the right attachement type (I'm new at this)<br>
BTW. here a some nice examples:<br>
<br>
- Get the number of attributes of the first childnode:<br>
<tt>select ( xpath('count(@*)',(xpath('*[1]','<a b="c"><d
e="f" g="j"/></a>'))[1]))[1];<br>
<br>
</tt>- an alternative for xpath_exist('/a/d')<br>
<tt>select (xpath('boolean(/a/d)','<a b="c"><d e="f"
g="j"/></a>'))[1];<br>
<br>
</tt>- fixes bug 4206<br>
<tt>select xpath('//text()',xmlparse(document '<?xml
version="1.0"?><elem1><elem2>one</elem2><elem2>two</elem2><elem2>three</elem2><elem3</tt><tt>att="2"/></elem1>'));<br>
</tt><tt><br>
</tt>- fixes bug 4294<br>
<tt>select xpath('name(/my:a/*[last()])', '<a
xmlns=<a class="moz-txt-link-rfc2396E" href="http://myns.com/ns">"http://myns.com/ns"</a>><b>text1</b><c>text2</c></a>',
ARRAY[ARRAY['my','<a class="moz-txt-link-freetext"
href="http://myns.com/ns">http://myns.com/ns</a>']]);<br>
<br>
</tt>kind regards, Arie Bikker<br>
</body>
</html>