BUG #3734: Invalid XML schema output.

Поиск
Список
Период
Сортировка
Искать

BUG #3734: Invalid XML schema output.

От:
"Ben Leslie" <benno@benno.id.au>
Дата:
The following bug has been logged online:

Bug reference:      3734
Logged by:          Ben Leslie
Email address:      benno@benno.id.au
PostgreSQL version: 8.3 beta2
Operating system:   Mac OS X
Description:        Invalid XML schema output.
Details: 

database_to_xml_and_xmlschema creates an invalid XML in certain
circumstances.

To recreate:

CREATE DATABASE test;
\c test
CREATE DOMAIN isoweek AS date CHECK (date_trunc('week', VALUE) = VALUE);
CREATE TABLE test (x isoweek);
INSERT INTO test VALUES ('2007-01-01');

Now to see the bug:

SELECT database_to_xml_and_xmlschema('t', 'f', '');

The output is:

 
 
 
 
 
   
 
 
 
   
     
   
 
 
 
   
     
   
 
 
 
 
 
 
 
 
 
 
 
   2007-01-01
 
 
 
 
 
 
 


The specific problem is that the following is malformed; the xsd:restriction
tag is never closed.

 
   
 

The correct output (as far as I can tell) should be:

 
   
 

Re: BUG #3734: Invalid XML schema output.

От:
Euler Taveira de Oliveira <euler@timbira.com>
Дата:
Ben Leslie wrote:

> The specific problem is that the following is malformed; the xsd:restriction
> tag is never closed.
> 
>  
>    
>  
> 
Exact. Per 9.11 (6, b, iv) or 9.15 (8, m, vi), it's a simple element.
The attached patch should fix it.
I'm attaching another small patch to strip some space and be consistent
with other xml tags.


-- 
  Euler Taveira de Oliveira
  http://www.timbira.com/
*** src/backend/utils/adt/xml.c.orig	2007-11-09 16:33:56.000000000 -0200
--- src/backend/utils/adt/xml.c	2007-11-09 16:37:30.000000000 -0200
***************
*** 2987,2993 ****
  					base_typeoid = getBaseTypeAndTypmod(typeoid, &base_typmod);
  
  					appendStringInfo(&result,
! 									 "  \n",
  									 map_sql_type_to_xml_name(base_typeoid, base_typmod));
  				}
  		}
--- 2987,2993 ----
  					base_typeoid = getBaseTypeAndTypmod(typeoid, &base_typmod);
  
  					appendStringInfo(&result,
! 									 "  \n",
  									 map_sql_type_to_xml_name(base_typeoid, base_typmod));
  				}
  		}
*** src/backend/utils/adt/xml.c.orig	2007-11-09 16:33:56.000000000 -0200
--- src/backend/utils/adt/xml.c	2007-11-09 17:01:50.000000000 -0200
***************
*** 2595,2605 ****
  
  		if (!tableforest)
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  		else
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  	}
  
--- 2595,2605 ----
  
  		if (!tableforest)
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  		else
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  	}
  
***************
*** 2656,2662 ****
  																		NULL);
  
  		appendStringInfo(&result,
! 						 "    \n",
  						 xmlsn, schematypename);
  	}
  
--- 2656,2662 ----
  																		NULL);
  
  		appendStringInfo(&result,
! 						 "    \n",
  						 xmlsn, schematypename);
  	}

Re: BUG #3734: Invalid XML schema output.

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Euler Taveira de Oliveira  writes:
> Ben Leslie wrote:
>> The specific problem is that the following is malformed; the xsd:restriction
>> tag is never closed.

> Exact. Per 9.11 (6, b, iv) or 9.15 (8, m, vi), it's a simple element.
> The attached patch should fix it.
> I'm attaching another small patch to strip some space and be consistent
> with other xml tags.

Applied, thanks.

			regards, tom lane

Re: BUG #3734: Invalid XML schema output.

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Euler Taveira de Oliveira wrote:
> I'm attaching another small patch to strip some space and be
> consistent with other xml tags.

Having a space before /> appears to be common practice, including in the 
examples in the SQL/XML spec.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: BUG #3734: Invalid XML schema output.

От:
Euler Taveira de Oliveira <euler@timbira.com>
Дата:
Peter Eisentraut wrote:

> Having a space before /> appears to be common practice, including in the 
> examples in the SQL/XML spec.
> 
Agreed. Feel free to add whitespace before every /> of simple xml elements.

-- 
  Euler Taveira de Oliveira
  http://www.timbira.com/

Re: BUG #3734: Invalid XML schema output.

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Euler Taveira de Oliveira wrote:
> Peter Eisentraut wrote:
> 
> > Having a space before /> appears to be common practice, including in the 
> > examples in the SQL/XML spec.
> > 
> Agreed. Feel free to add whitespace before every /> of simple xml elements.

Uh, was this done?

-- 
  Bruce Momjian          http://momjian.us
  EnterpriseDB                             http://postgres.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: BUG #3734: Invalid XML schema output.

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Bruce Momjian wrote:
> Euler Taveira de Oliveira wrote:
> > Peter Eisentraut wrote:
> > > Having a space before /> appears to be common practice, including in
> > > the examples in the SQL/XML spec.
> >
> > Agreed. Feel free to add whitespace before every /> of simple xml
> > elements.
>
> Uh, was this done?

I didn't want to bother.  It seems alright as it is.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: BUG #3734: Invalid XML schema output.

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Peter Eisentraut wrote:
> Bruce Momjian wrote:
> > Euler Taveira de Oliveira wrote:
> > > Peter Eisentraut wrote:
> > > > Having a space before /> appears to be common practice, including in
> > > > the examples in the SQL/XML spec.
> > >
> > > Agreed. Feel free to add whitespace before every /> of simple xml
> > > elements.
> >
> > Uh, was this done?
> 
> I didn't want to bother.  It seems alright as it is.

OK, I kept the idea for 8.4, just in case.

-- 
  Bruce Momjian          http://momjian.us
  EnterpriseDB                             http://postgres.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: BUG #3734: Invalid XML schema output.

От:
Euler Taveira de Oliveira <euler@timbira.com>
Дата:
Bruce Momjian wrote:

>> Agreed. Feel free to add whitespace before every /> of simple xml elements.
> 
> Uh, was this done?
> 
Nope. Attached is a patch that does it. I'm attaching another cosmetic
patch that replaces the use of some single quotes with double quotes in
the XML attributes output.


-- 
  Euler Taveira de Oliveira
  http://www.timbira.com/
*** ./src/backend/utils/adt/xml.c.orig	2007-11-23 01:55:00.000000000 -0200
--- ./src/backend/utils/adt/xml.c	2007-11-23 02:01:24.000000000 -0200
***************
*** 2641,2658 ****
  		appendStringInfo(&result,
  						 "\n"
  						 "  \n"
! 						 "    \n"
  						 "  \n"
  						 "\n\n",
  						 tabletypename, rowtypename);
  
  		appendStringInfo(&result,
! 						 "\n\n",
  						 xmltn, tabletypename);
  	}
  	else
  		appendStringInfo(&result,
! 						 "\n\n",
  						 xmltn, rowtypename);
  
  	xsd_schema_element_end(&result);
--- 2641,2658 ----
  		appendStringInfo(&result,
  						 "\n"
  						 "  \n"
! 						 "    \n"
  						 "  \n"
  						 "\n\n",
  						 tabletypename, rowtypename);
  
  		appendStringInfo(&result,
! 						 "\n\n",
  						 xmltn, tabletypename);
  	}
  	else
  		appendStringInfo(&result,
! 						 "\n\n",
  						 xmltn, rowtypename);
  
  	xsd_schema_element_end(&result);
***************
*** 2709,2719 ****
  
  		if (!tableforest)
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  		else
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  	}
  
--- 2709,2719 ----
  
  		if (!tableforest)
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  		else
  			appendStringInfo(&result,
! 							 "    \n",
  							 xmltn, tabletypename);
  	}
  
***************
*** 2727,2733 ****
  						   "\n\n");
  
  	appendStringInfo(&result,
! 					 "\n\n",
  					 xmlsn, schematypename);
  
  	return result.data;
--- 2727,2733 ----
  						   "\n\n");
  
  	appendStringInfo(&result,
! 					 "\n\n",
  					 xmlsn, schematypename);
  
  	return result.data;
***************
*** 2775,2781 ****
  																	   NULL);
  
  		appendStringInfo(&result,
! 						 "    \n",
  						 xmlsn, schematypename);
  	}
  
--- 2775,2781 ----
  																	   NULL);
  
  		appendStringInfo(&result,
! 						 "    \n",
  						 xmlsn, schematypename);
  	}
  
***************
*** 2785,2791 ****
  						   "\n\n");
  
  	appendStringInfo(&result,
! 					 "\n\n",
  					 xmlcn, catalogtypename);
  
  	return result.data;
--- 2785,2791 ----
  						   "\n\n");
  
  	appendStringInfo(&result,
! 					 "\n\n",
  					 xmlcn, catalogtypename);
  
  	return result.data;
***************
*** 2969,2975 ****
  		appendStringInfo(&result,
  						 "\n"
  						 "  \n"
! 						 "    \n"
  						 "  \n"
  						 "\n");
  	}
--- 2969,2975 ----
  		appendStringInfo(&result,
  						 "\n"
  						 "  \n"
! 						 "    \n"
  						 "  \n"
  						 "\n");
  	}
***************
*** 2986,2992 ****
  				if (typmod != -1)
  					appendStringInfo(&result,
  								  "  \n"
! 									 "    \n"
  									 "  \n",
  									 typmod - VARHDRSZ);
  				break;
--- 2986,2992 ----
  				if (typmod != -1)
  					appendStringInfo(&result,
  								  "  \n"
! 									 "    \n"
  									 "  \n",
  									 typmod - VARHDRSZ);
  				break;
***************
*** 3001,3008 ****
  				if (typmod != -1)
  					appendStringInfo(&result,
  								 "  \n"
! 									 "    \n"
! 								   "    \n"
  									 "  \n",
  									 ((typmod - VARHDRSZ) >> 16) & 0xffff,
  									 (typmod - VARHDRSZ) & 0xffff);
--- 3001,3008 ----
  				if (typmod != -1)
  					appendStringInfo(&result,
  								 "  \n"
! 									 "    \n"
! 								   "    \n"
  									 "  \n",
  									 ((typmod - VARHDRSZ) >> 16) & 0xffff,
  									 (typmod - VARHDRSZ) & 0xffff);
***************
*** 3011,3018 ****
  			case INT2OID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
! 								 "    \n"
  								 "  \n",
  								 SHRT_MAX, SHRT_MIN);
  				break;
--- 3011,3018 ----
  			case INT2OID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
! 								 "    \n"
  								 "  \n",
  								 SHRT_MAX, SHRT_MIN);
  				break;
***************
*** 3020,3027 ****
  			case INT4OID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
! 								 "    \n"
  								 "  \n",
  								 INT_MAX, INT_MIN);
  				break;
--- 3020,3027 ----
  			case INT4OID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
! 								 "    \n"
  								 "  \n",
  								 INT_MAX, INT_MIN);
  				break;
***************
*** 3029,3036 ****
  			case INT8OID:
  				appendStringInfo(&result,
  								 "  \n"
! 					   "    \n"
! 					   "    \n"
  								 "  \n",
  							   (((uint64) 1) << (sizeof(int64) * 8 - 1)) - 1,
  								 (((uint64) 1) << (sizeof(int64) * 8 - 1)));
--- 3029,3036 ----
  			case INT8OID:
  				appendStringInfo(&result,
  								 "  \n"
! 					   "    \n"
! 					   "    \n"
  								 "  \n",
  							   (((uint64) 1) << (sizeof(int64) * 8 - 1)) - 1,
  								 (((uint64) 1) << (sizeof(int64) * 8 - 1)));
***************
*** 3059,3075 ****
  					if (typmod == -1)
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else if (typmod == 0)
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  							"  \n", typmod - VARHDRSZ, tz);
  					break;
  				}
--- 3059,3075 ----
  					if (typmod == -1)
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else if (typmod == 0)
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else
  						appendStringInfo(&result,
  									"  \n"
! 										 "    \n"
  							"  \n", typmod - VARHDRSZ, tz);
  					break;
  				}
***************
*** 3082,3098 ****
  					if (typmod == -1)
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else if (typmod == 0)
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  							"  \n", typmod - VARHDRSZ, tz);
  					break;
  				}
--- 3082,3098 ----
  					if (typmod == -1)
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else if (typmod == 0)
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  										 "  \n", tz);
  					else
  						appendStringInfo(&result,
  								"  \n"
! 										 "    \n"
  							"  \n", typmod - VARHDRSZ, tz);
  					break;
  				}
***************
*** 3100,3106 ****
  			case DATEOID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
  								 "  \n");
  				break;
  
--- 3100,3106 ----
  			case DATEOID:
  				appendStringInfo(&result,
  								 "  \n"
! 								 "    \n"
  								 "  \n");
  				break;
  
***************
*** 3113,3119 ****
  					base_typeoid = getBaseTypeAndTypmod(typeoid, &base_typmod);
  
  					appendStringInfo(&result,
! 									 "  \n",
  						map_sql_type_to_xml_name(base_typeoid, base_typmod));
  				}
  				break;
--- 3113,3119 ----
  					base_typeoid = getBaseTypeAndTypmod(typeoid, &base_typmod);
  
  					appendStringInfo(&result,
! 									 "  \n",
  						map_sql_type_to_xml_name(base_typeoid, base_typmod));
  				}
  				break;
***************
*** 3168,3174 ****
  		if (isnull)
  		{
  			if (nulls)
! 				appendStringInfo(result, "  <%s xsi:nil='true'/>\n", colname);
  		}
  		else
  			appendStringInfo(result, "  <%s>%s\n",
--- 3168,3174 ----
  		if (isnull)
  		{
  			if (nulls)
! 				appendStringInfo(result, "  <%s xsi:nil='true' />\n", colname);
  		}
  		else
  			appendStringInfo(result, "  <%s>%s\n",
*** ./src/backend/utils/adt/xml.c.orig	2007-11-23 02:17:55.000000000 -0200
--- ./src/backend/utils/adt/xml.c	2007-11-23 02:21:31.000000000 -0200
***************
*** 3019,3025 ****
  
  			case INT4OID:
  				appendStringInfo(&result,
! 								 "  \n"
  								 "    \n"
  								 "    \n"
  								 "  \n",
--- 3019,3025 ----
  
  			case INT4OID:
  				appendStringInfo(&result,
! 								 "  \n"
  								 "    \n"
  								 "    \n"
  								 "  \n",
***************
*** 3168,3174 ****
  		if (isnull)
  		{
  			if (nulls)
! 				appendStringInfo(result, "  <%s xsi:nil='true' />\n", colname);
  		}
  		else
  			appendStringInfo(result, "  <%s>%s\n",
--- 3168,3174 ----
  		if (isnull)
  		{
  			if (nulls)
! 				appendStringInfo(result, "  <%s xsi:nil=\"true\" />\n", colname);
  		}
  		else
  			appendStringInfo(result, "  <%s>%s\n",

Re: BUG #3734: Invalid XML schema output.

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Euler Taveira de Oliveira  writes:
> Bruce Momjian wrote:
>>> Agreed. Feel free to add whitespace before every /> of simple xml elements.
>> 
>> Uh, was this done?
>> 
> Nope. Attached is a patch that does it.

Er ... why exactly is it a good idea to bloat XML output with cosmetic
whitespace?  I should think that only programs, not humans, read XML for
the most part.

> I'm attaching another cosmetic
> patch that replaces the use of some single quotes with double quotes in
> the XML attributes output.

This part sounds like a good idea, if only because single quotes require
doubling in some situations in SQL-land.

			regards, tom lane

Re: BUG #3734: Invalid XML schema output.

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Tom Lane wrote:
> Euler Taveira de Oliveira  writes:
> > Bruce Momjian wrote:
> >>> Agreed. Feel free to add whitespace before every /> of simple xml elements.
> >> 
> >> Uh, was this done?
> >> 
> > Nope. Attached is a patch that does it.
> 
> Er ... why exactly is it a good idea to bloat XML output with cosmetic
> whitespace?  I should think that only programs, not humans, read XML for
> the most part.

I assumed XML is for both human and program reading;  in fact, I thought
that was its big benefit.  I assume we are taking the difference between
"
" vs "
", right? I will admit I don't know much about XML. -- Bruce Momjian http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +

Re: BUG #3734: Invalid XML schema output.

От:
"Harald Armin Massa" <haraldarminmassa@gmail.com>
Дата:
>
> I assumed XML is for both human and program reading;  in fact, I thought
> that was its big benefit.  I assume we are taking the difference between
> "
" vs "
", right? I will admit I don't know much about XML. > > within XHTML it is recommended to use
, because some parsers will not parse it correctly without that space. I guess some pure XML-Parsers may have the same problem (and be it only the IE-XML-Parser) Harald --=20 GHUM Harald Massa persuadere et programmare Harald Armin Massa Spielberger Stra=DFe 49 70435 Stuttgart 0173/9409607 fx 01212-5-13695179 - EuroPython 2008 will take place in Vilnius, Lithuania - Stay tuned!

Re: BUG #3734: Invalid XML schema output.

От:
Michael Glaesemann <grzm@seespotcode.net>
Дата:
On Nov 23, 2007, at 11:22 , Harald Armin Massa wrote:

> within XHTML it is recommended to use 
, because some parsers > will not parse it correctly without that space. It's because some browser *HTML* parsers that aren't fully XML compliant won't parse it correctly, not because some XML parsers have a problem with it. Any XML parser worthy of the name should have no problem with
(or any other self-closing empty element tag, for that matter). Michael Glaesemann grzm seespotcode net

Re: BUG #3734: Invalid XML schema output.

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Am Freitag, 23. November 2007 schrieb Michael Glaesemann:
> It's because some browser *HTML* parsers that aren't fully XML  
> compliant won't parse it correctly

Yes, that is pretty much it, but that is obviously irrelevant nowadays and for 
us, especially.  Some sources seem to use it for stylistic reasons, but I 
fail to see the advantage.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: BUG #3734: Invalid XML schema output.

От:
Michael Glaesemann <grzm@seespotcode.net>
Дата:
On Nov 23, 2007, at 12:30 , Peter Eisentraut wrote:

> Am Freitag, 23. November 2007 schrieb Michael Glaesemann:
>> It's because some browser *HTML* parsers that aren't fully XML
>> compliant won't parse it correctly
>
> Yes, that is pretty much it, but that is obviously irrelevant  
> nowadays and for
> us, especially.  Some sources seem to use it for stylistic reasons,  
> but I
> fail to see the advantage.

Agreed.

Michael Glaesemann
grzm seespotcode net

Re: BUG #3734: Invalid XML schema output.

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Euler Taveira de Oliveira wrote:
> Bruce Momjian wrote:
> >> Agreed. Feel free to add whitespace before every /> of simple xml
> >> elements.
> >
> > Uh, was this done?
>
> Nope. Attached is a patch that does it. I'm attaching another cosmetic
> patch that replaces the use of some single quotes with double quotes in
> the XML attributes output.

I have committed the quoting changes.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/
FAQ