Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function - Mailing list pgsql-hackers

From Mike Fowler
Subject Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function
Date
Msg-id 4C28D05F.8030005@mlfowler.com
Whole thread Raw
In response to Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function  (Mike Fowler <mike@mlfowler.com>)
List pgsql-hackers
Robert Haas wrote:
> On Mon, Jun 28, 2010 at 11:42 AM, Mike Rylander <mrylander@gmail.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'



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: get_whatever_oid, part 1: object types with unqualifed names
Next
From: Robert Haas
Date:
Subject: Re: get_whatever_oid, part 1: object types with unqualifed names