From: | Scott Bailey <artacus(at)comcast(dot)net> |
---|---|
To: | Arie Bikker <arie(at)abikker(dot)nl> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: xpath improvement suggestion |
Date: | 2010-01-07 00:32:41 |
Message-ID: | 4B452BA9.1030307@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Arie Bikker wrote:
> Sorry for the previous NUUUB post, didn't now the mailing list doesn't
> support html ;(
> Robert Haas wrote:
>> On Tue, Jan 5, 2010 at 6:09 PM, Arie Bikker <arie(at)abikker(dot)nl> wrote:
>>
>>> 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
>>> http://archives.postgresql.org/pgsql-hackers/2008-06/msg00616.php 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
>>>
>>
>> Hi,
>>
>> Could you please resend this as a context diff and add it to our patch
>> management application?
>>
>> http://wiki.postgresql.org/wiki/Submitting_a_Patch
>> https://commitfest.postgresql.org/action/commitfest_view/open
>>
>> Thanks!
>>
>> ...Robert
>>
> Hope this is the right attachement type (I'm new at this)
> BTW. here a some nice examples:
>
> - Get the number of attributes of the first childnode:
>
> select ( xpath('count(@*)',(xpath('*[1]','<a b="c"><d e="f"
> g="j"/></a>'))[1]))[1];
>
> - an alternative for xpath_exist('/a/d')
> select (xpath('boolean(/a/d)','<a b="c"><d e="f" g="j"/></a>'))[1];
>
> - fixes bug 4206
>
> select xpath('//text()',xmlparse(document '<?xml
> version="1.0"?><elem1><elem2>one</elem2><elem2>two</elem2><elem2>three</elem2><elem3att="2"/></elem1>'));
>
>
> - fixes bug 4294
>
> select xpath('name(/my:a/*[last()])', '<a
> xmlns="http://myns.com/ns"><b>text1</b><c>text2</c></a>',
> ARRAY[ARRAY['my','http://myns.com/ns']]);
Awesome! This really helps.
Scott
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2010-01-07 00:40:30 | Re: unresolved bugs |
Previous Message | Andrew Dunstan | 2010-01-07 00:07:12 | Re: Testing plperl<->plperlu interaction |