|
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.36 2007/03/22 20:14:58 momjian Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.37 2007/03/22 20:26:30 momjian Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
@@ -91,7 +91,7 @@ static xmlChar *xml_text2xmlChar(text *in); |
91 | 91 | staticintparse_xml_decl(constxmlChar*str,size_t*lenp,xmlChar**version,xmlChar**encoding,int*standalone); |
92 | 92 | staticboolprint_xml_decl(StringInfobuf,constxmlChar*version,pg_encencoding,intstandalone); |
93 | 93 | staticxmlDocPtrxml_parse(text*data,XmlOptionTypexmloption_arg,boolpreserve_whitespace,xmlChar*encoding); |
94 | | -statictext*xml_xmlnodetotext(xmlNodePtrcur); |
| 94 | +statictext*xml_xmlnodetoxmltype(xmlNodePtrcur); |
95 | 95 |
|
96 | 96 | #endif/* USE_LIBXML */ |
97 | 97 |
|
@@ -2414,20 +2414,31 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, bool n |
2414 | 2414 |
|
2415 | 2415 | #ifdefUSE_LIBXML |
2416 | 2416 | /* |
2417 | | - * Convert XML node to text (return value only, it's not dumping) |
| 2417 | + * Convert XML node to text (dump subtree in case of element, return value otherwise) |
2418 | 2418 | */ |
2419 | 2419 | text* |
2420 | | -xml_xmlnodetotext(xmlNodePtrcur) |
| 2420 | +xml_xmlnodetoxmltype(xmlNodePtrcur) |
2421 | 2421 | { |
2422 | | -xmlChar*str; |
2423 | | -text*result; |
2424 | | -size_tlen; |
| 2422 | +xmlChar*str; |
| 2423 | +xmltype*result; |
| 2424 | +size_tlen; |
| 2425 | +xmlBufferPtrbuf; |
2425 | 2426 |
|
2426 | | -str=xmlXPathCastNodeToString(cur); |
2427 | | -len=strlen((char*)str); |
2428 | | -result= (text*)palloc(len+VARHDRSZ); |
2429 | | -SET_VARSIZE(result,len+VARHDRSZ); |
2430 | | -memcpy(VARDATA(result),str,len); |
| 2427 | +if (cur->type==XML_ELEMENT_NODE) |
| 2428 | +{ |
| 2429 | +buf=xmlBufferCreate(); |
| 2430 | +xmlNodeDump(buf,NULL,cur,0,1); |
| 2431 | +result=xmlBuffer_to_xmltype(buf); |
| 2432 | +xmlBufferFree(buf); |
| 2433 | +} |
| 2434 | +else |
| 2435 | +{ |
| 2436 | +str=xmlXPathCastNodeToString(cur); |
| 2437 | +len=strlen((char*)str); |
| 2438 | +result= (text*)palloc(len+VARHDRSZ); |
| 2439 | +SET_VARSIZE(result,len+VARHDRSZ); |
| 2440 | +memcpy(VARDATA(result),str,len); |
| 2441 | +} |
2431 | 2442 |
|
2432 | 2443 | returnresult; |
2433 | 2444 | } |
@@ -2607,7 +2618,7 @@ xmlpath(PG_FUNCTION_ARGS) |
2607 | 2618 | { |
2608 | 2619 | Datumelem; |
2609 | 2620 | boolelemisnull= false; |
2610 | | -elem=PointerGetDatum(xml_xmlnodetotext(xpathobj->nodesetval->nodeTab[i])); |
| 2621 | +elem=PointerGetDatum(xml_xmlnodetoxmltype(xpathobj->nodesetval->nodeTab[i])); |
2611 | 2622 | astate=accumArrayResult(astate,elem, |
2612 | 2623 | elemisnull,XMLOID, |
2613 | 2624 | CurrentMemoryContext); |
|