*** a/src/backend/utils/adt/xml.c
--- b/src/backend/utils/adt/xml.c
***************
*** 2001,2006 **** map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
--- 2001,2009 ----
  		bool		isvarlena;
  		char	   *str;
  
+ 		/* flatten domains */
+ 		type = getBaseType(type);
+ 
  		/*
  		 * Special XSD formatting for some data types
  		 */
*** a/src/test/regress/expected/xmlmap.out
--- b/src/test/regress/expected/xmlmap.out
***************
*** 1174,1176 **** SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
--- 1174,1200 ----
   
  (1 row)
  
+ -- domain should be transformed correctly to - a result should be same as base types
+ CREATE DOMAIN testboolxmldomain AS bool;
+ CREATE DOMAIN testdatexmldomain AS date;
+ CREATE TABLE testxmlschema.test3 AS SELECT true c1, true::testboolxmldomain c2,
+                                            '2013-02-21'::date c3, '2013-02-21'::testdatexmldomain c4;
+ SELECT xmlforest(c1, c2, c3, c4) FROM testxmlschema.test3;
+                             xmlforest                             
+ ------------------------------------------------------------------
+  <c1>true</c1><c2>true</c2><c3>2013-02-21</c3><c4>2013-02-21</c4>
+ (1 row)
+ 
+ select table_to_xml('testxmlschema.test3', true, true, '');
+                          table_to_xml                          
+ ---------------------------------------------------------------
+  <test3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
+    <c1>true</c1>                                              +
+    <c2>true</c2>                                              +
+    <c3>2013-02-21</c3>                                        +
+    <c4>2013-02-21</c4>                                        +
+  </test3>                                                     +
+                                                               +
+  
+ (1 row)
+ 
*** a/src/test/regress/sql/xmlmap.sql
--- b/src/test/regress/sql/xmlmap.sql
***************
*** 39,41 **** SELECT schema_to_xml('testxmlschema', true, false, '');
--- 39,51 ----
  SELECT schema_to_xmlschema('testxmlschema', false, true, '');
  SELECT schema_to_xmlschema('testxmlschema', true, false, '');
  SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
+ 
+ -- domain should be transformed correctly to - a result should be same as base types
+ CREATE DOMAIN testboolxmldomain AS bool;
+ CREATE DOMAIN testdatexmldomain AS date;
+ 
+ CREATE TABLE testxmlschema.test3 AS SELECT true c1, true::testboolxmldomain c2,
+                                            '2013-02-21'::date c3, '2013-02-21'::testdatexmldomain c4;
+ 
+ SELECT xmlforest(c1, c2, c3, c4) FROM testxmlschema.test3;
+ select table_to_xml('testxmlschema.test3', true, true, '');
