77 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.12 2007/01/0700:13:55 petere Exp $
10+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.13 2007/01/0722:49:56 petere Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -257,18 +257,26 @@ xmlparse(text *data, bool is_document, bool preserve_whitespace)
257257
258258
259259xmltype *
260- xmlpi (char * target ,text * arg )
260+ xmlpi (char * target ,text * arg , bool arg_is_null , bool * result_is_null )
261261{
262262#ifdef USE_LIBXML
263263xmltype * result ;
264264StringInfoData buf ;
265265
266266if (pg_strncasecmp (target ,"xml" ,3 )== 0 )
267267ereport (ERROR ,
268- (errcode (ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION ),
268+ (errcode (ERRCODE_SYNTAX_ERROR ), /* really */
269269errmsg ("invalid XML processing instruction" ),
270270errdetail ("XML processing instruction target name cannot start with \"xml\"." )));
271271
272+ /*
273+ * Following the SQL standard, the null check comes after the
274+ * syntax check above.
275+ */
276+ * result_is_null = arg_is_null ;
277+ if (* result_is_null )
278+ return NULL ;
279+
272280initStringInfo (& buf );
273281
274282appendStringInfo (& buf ,"<?%s" ,target );
@@ -286,7 +294,7 @@ xmlpi(char *target, text *arg)
286294errdetail ("XML processing instruction cannot contain \"?>\"." )));
287295
288296appendStringInfoChar (& buf ,' ' );
289- appendStringInfoString (& buf ,string );
297+ appendStringInfoString (& buf ,string + strspn ( string , " " ) );
290298pfree (string );
291299}
292300appendStringInfoString (& buf ,"?>" );