Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function

From: Mike Fowler <mike(at)mlfowler(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Mike Rylander <mrylander(at)gmail(dot)com>, Mike Berrow <mberrow(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function
Date: 2010-06-28 16:39:59
Message-ID: 4C28D05F.8030005@mlfowler.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas wrote:
> On Mon, Jun 28, 2010 at 11:42 AM, Mike Rylander <mrylander(at)gmail(dot)com> wrote:
>
>> You could do something like this (untested):
>>
>> CREATE OR REPLACE FUNCTION my_xml_is_valid ( x TEXT ) RETURNS BOOL AS $$
>> BEGIN
>> PERFORM XMLPARSE( DOCUMENT x::XML );
>> RETURN TRUE;
>> EXCEPTION WHEN OTHERS THEN
>> RETURN FALSE;
>> END;
>> $$ LANGUAGE PLPGSQL;
>>
>
> This might perform significantly worse, though: exception handling ain't cheap.
>
> It's not a bad workaround, but I think the OP has a point.
>
>
Should the IS DOCUMENT predicate support this? At the moment you get the
following:

template1=# SELECT
'<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns>'
IS DOCUMENT;
?column?
----------
t
(1 row)

template1=# SELECT
'<towns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns'
IS DOCUMENT;
ERROR: invalid XML content
LINE 1: SELECT '<towns><town>Bidford-on-Avon</town><town>Cwmbran</to...
^
DETAIL: Entity: line 1: parser error : expected '>'
owns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns

^
Entity: line 1: parser error : chunk is not well balanced
owns><town>Bidford-on-Avon</town><town>Cwmbran</town><town>Bristol</town></towns

^
I would've hoped the second would've returned 'f' rather than failing.
I've had a glance at the XML/SQL standard and I don't see anything in
the detail of the predicate (8.2) that would specifically prohibit us
from changing this behavior, unless the common rule 'Parsing a string
as an XML value' (10.16) must always be in force. I'm no standard
expert, but IMHO this would be an acceptable change to improve
usability. What do others think?

Regards,

--
Mike Fowler
Registered Linux user: 379787

"I could be a genius if I just put my mind to it, and I,
I could do anything, if only I could get 'round to it"
-PULP 'Glory Days'

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2010-06-28 16:41:57 Re: get_whatever_oid, part 1: object types with unqualifed names
Previous Message Tom Lane 2010-06-28 16:31:56 Re: get_whatever_oid, part 1: object types with unqualifed names