|
7 | 7 | * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.19 2007/01/19 16:58:46 petere Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.20 2007/01/20 09:27:19 petere Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -359,6 +359,102 @@ xmlcomment(PG_FUNCTION_ARGS)
|
359 | 359 | }
|
360 | 360 |
|
361 | 361 |
|
| 362 | + |
| 363 | +/* |
| 364 | + * TODO: xmlconcat needs to merge the notations and unparsed entities |
| 365 | + * of the argument values. Not very important in practice, though. |
| 366 | + */ |
| 367 | +xmltype* |
| 368 | +xmlconcat(List*args) |
| 369 | +{ |
| 370 | +#ifdefUSE_LIBXML |
| 371 | +StringInfoDatabuf; |
| 372 | +ListCell*v; |
| 373 | + |
| 374 | +intglobal_standalone=1; |
| 375 | +xmlChar*global_version=NULL; |
| 376 | +boolglobal_version_no_value= false; |
| 377 | + |
| 378 | +initStringInfo(&buf); |
| 379 | +foreach(v,args) |
| 380 | +{ |
| 381 | +size_tlen; |
| 382 | +xmlChar*version; |
| 383 | +intstandalone; |
| 384 | +xmltype*x=DatumGetXmlP(PointerGetDatum(lfirst(v))); |
| 385 | +char*str; |
| 386 | + |
| 387 | +len=VARSIZE(x)-VARHDRSZ; |
| 388 | +str=palloc(len+1); |
| 389 | +memcpy(str,VARDATA(x),len); |
| 390 | +str[len]='\0'; |
| 391 | + |
| 392 | +parse_xml_decl((xmlChar*)str,&len,&version,NULL,&standalone); |
| 393 | + |
| 394 | +if (standalone==0&&global_standalone==1) |
| 395 | +global_standalone=0; |
| 396 | +if (standalone<0) |
| 397 | +global_standalone=-1; |
| 398 | + |
| 399 | +if (!global_version) |
| 400 | +global_version=xmlStrdup(version); |
| 401 | +elseif (version&&xmlStrcmp(version,global_version)!=0) |
| 402 | +global_version_no_value= true; |
| 403 | + |
| 404 | +appendStringInfoString(&buf,str+len); |
| 405 | +pfree(str); |
| 406 | +} |
| 407 | + |
| 408 | +if (!global_version_no_value||global_standalone >=0) |
| 409 | +{ |
| 410 | +StringInfoDatabuf2; |
| 411 | + |
| 412 | +initStringInfo(&buf2); |
| 413 | + |
| 414 | +if (!global_version_no_value&&global_version) |
| 415 | +appendStringInfo(&buf2,"<?xml version=\"%s\"",global_version); |
| 416 | +else |
| 417 | +appendStringInfo(&buf2,"<?xml version=\"%s\"",PG_XML_DEFAULT_VERSION); |
| 418 | + |
| 419 | +if (global_standalone==1) |
| 420 | +appendStringInfoString(&buf2," standalone=\"yes\""); |
| 421 | +elseif (global_standalone==0) |
| 422 | +appendStringInfoString(&buf2," standalone=\"no\""); |
| 423 | + |
| 424 | +appendStringInfoString(&buf2,"?>"); |
| 425 | + |
| 426 | +appendStringInfoString(&buf2,buf.data); |
| 427 | +buf=buf2; |
| 428 | +} |
| 429 | + |
| 430 | +returnstringinfo_to_xmltype(&buf); |
| 431 | +#else |
| 432 | +NO_XML_SUPPORT(); |
| 433 | +returnNULL; |
| 434 | +#endif |
| 435 | +} |
| 436 | + |
| 437 | + |
| 438 | +/* |
| 439 | + * XMLAGG support |
| 440 | + */ |
| 441 | +Datum |
| 442 | +xmlconcat2(PG_FUNCTION_ARGS) |
| 443 | +{ |
| 444 | +if (PG_ARGISNULL(0)) |
| 445 | +{ |
| 446 | +if (PG_ARGISNULL(1)) |
| 447 | +PG_RETURN_NULL(); |
| 448 | +else |
| 449 | +PG_RETURN_XML_P(PG_GETARG_XML_P(1)); |
| 450 | +} |
| 451 | +elseif (PG_ARGISNULL(1)) |
| 452 | +PG_RETURN_XML_P(PG_GETARG_XML_P(0)); |
| 453 | +else |
| 454 | +PG_RETURN_XML_P(xmlconcat(list_make2(PG_GETARG_XML_P(0),PG_GETARG_XML_P(1)))); |
| 455 | +} |
| 456 | + |
| 457 | + |
362 | 458 | Datum
|
363 | 459 | texttoxml(PG_FUNCTION_ARGS)
|
364 | 460 | {
|
|