Skip site navigation (1) Skip section navigation (2)

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

From: Mike Rylander <mrylander(at)gmail(dot)com>
To: Mike Berrow <mberrow(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Issue: Deprecation of the XML2 module 'xml_is_well_formed' function
Date: 2010-06-28 15:42:15
Message-ID: AANLkTilLQW3iPS-WMNRHX5RACgS_dgmeqiFo4_AGYT0m@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Mon, Jun 28, 2010 at 11:08 AM, Mike Berrow <mberrow(at)gmail(dot)com> wrote:
> We need to make extensive use of the 'xml_is_well_formed' function provided
> by the XML2 module.
> Yet the documentation says that the xml2 module will be deprecated since
> "XML syntax checking and XPath queries"
> is covered by the XML-related functionality based on the SQL/XML standard in
> the core server from PostgreSQL 8.3 onwards.
> However, the core function XMLPARSE does not provide equivalent
> functionality since when it detects an invalid XML document,
> it throws an error rather than returning a truth value (which is what we
> need and currently have with the 'xml_is_well_formed' function).
> For example:
> select xml_is_well_formed('<br></br2>');
>  xml_is_well_formed
> --------------------
>  f
> (1 row)
> select XMLPARSE( DOCUMENT '<br></br2>' );
> ERROR:  invalid XML document
> DETAIL:  Entity: line 1: parser error : expected '>'
> <br></br2>
>         ^
> Entity: line 1: parser error : Extra content at the end of the document
> <br></br2>
>         ^
> Is there some way to use the new, core XML functionality to simply return a
> truth value
> in the way that we need?.

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;

-- 
Mike Rylander
 | VP, Research and Design
 | Equinox Software, Inc. / The Evergreen Experts
 | phone:  1-877-OPEN-ILS (673-6457)
 | email:  miker(at)esilibrary(dot)com
 | web:  http://www.esilibrary.com

In response to

Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2010-06-28 15:44:04
Subject: Re: get_whatever_oid, part 1: object types with unqualifed names
Previous:From: Kevin GrittnerDate: 2010-06-28 15:32:20
Subject: Re: Built-in connection pool

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group