diff --git a/compiler2/Makefile b/compiler2/Makefile
index 9ee5cd08e9f819676ce0bbf68b8ac375fd6c730f..d00ff26bdb63eb779b44405c35645452b0efe5d1 100644
--- a/compiler2/Makefile
+++ b/compiler2/Makefile
@@ -87,7 +87,7 @@ CompField.cc CompType.cc EnumItem.cc Identifier.cc Int.cc \
 main.cc Real.cc Setting.cc SigParam.cc string.cc subtype.cc Stopwatch.cc \
 Type.cc Type_chk.cc Type_codegen.cc TypeCompat.cc \
 Typestuff.cc ustring.cc Value.cc Valuestuff.cc XerAttributes.cc subtypestuff.cc \
-CodeGenHelper.cc DebuggerStuff.cc
+CodeGenHelper.cc DebuggerStuff.cc XSD_Types.cc
 
 MFGEN_SOURCES := makefile.c xpather.cc ProjectGenHelper.cc
 
diff --git a/compiler2/Type_codegen.cc b/compiler2/Type_codegen.cc
index 8d44ec3ba5fe620c64c6fd923a49f0a4790ddded..019cb1803f9c8c2b7b5933d4d3086131d431a418 100644
--- a/compiler2/Type_codegen.cc
+++ b/compiler2/Type_codegen.cc
@@ -28,6 +28,7 @@
 #include "union.h"
 #include "record_of.h"
 #include "functionref.h"
+#include "XSD_Types.hh"
 
 
 #include "ttcn3/Ttcnstuff.hh"
@@ -506,6 +507,7 @@ void Type::generate_code_xerdescriptor(output_struct* target)
   text=0, untagged=0, use_nil=0, use_number=0, use_order=0, use_qname=0,
   use_type_attr=0, ws=0, has_1untag=0, form_qualified=0, any_from=0, 
   any_except=0, nof_ns_uris=0, blocked=0, fractionDigits=-1;
+  const char* xsd_type = "XSD_NONE";
   const char* dfe_str = 0;
   char** ns_uris = 0;
   char* oftype_descr_name = 0;
@@ -541,6 +543,8 @@ void Type::generate_code_xerdescriptor(output_struct* target)
     // (encoder's choice) for USE-UNION. However, TTCN-3 removes this choice:
     // it is mandatory to use it when possible (valid choice for ASN.1 too).
     use_type_attr = xerattrib->useType_ || xerattrib->useUnion_;
+    
+    xsd_type = XSD_type_to_string(xerattrib->xsd_type);
 
     if (xerattrib->defaultValue_) {
       Type *t = xerattrib->defaultValue_->get_my_governor();
@@ -625,7 +629,7 @@ void Type::generate_code_xerdescriptor(output_struct* target)
   target->source.global_vars = mputprintf(target->source.global_vars,
     "const XERdescriptor_t       %s_xer_ = { {\"%s>\\n\", \"%s>\\n\"},"
     " {%lu, %lu}, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s, WHITESPACE_%s, %c%s, "
-    "&%s, %ld, %u, %s, %s, %i };\n",
+    "&%s, %ld, %u, %s, %s, %i, %s };\n",
     gennameown_str,
     bxer_name.c_str(), last_s.c_str(), // names
     (unsigned long)bxer_len, (unsigned long)last_len, // lengths
@@ -656,7 +660,8 @@ void Type::generate_code_xerdescriptor(output_struct* target)
     nof_ns_uris,
     (ns_uris_var ? ns_uris_var : "NULL"),
     (oftype_descr_name ? oftype_descr_name : "NULL"),
-    fractionDigits
+    fractionDigits,
+    xsd_type
     );
   
   Free(ns_uris_var);
@@ -1182,6 +1187,10 @@ void Type::generate_code_Choice(output_struct *target)
     if (xerattrib) {
       if (cftype->has_empty_xml()) sdef.exerMaybeEmptyIndex = i;
       // This will overwrite lower values, which is what we want.
+      
+      if (cftype->xerattrib != NULL) {
+        sdef.elements[i].xsd_type = cftype->xerattrib->xsd_type;
+      }
     }
     if (sdef.jsonAsValue) {
       // Determine the JSON value type of each field to make decoding faster
@@ -1336,7 +1345,7 @@ void Type::generate_code_Choice(output_struct *target)
     sdef.control_ns_prefix = prefix;
     sdef.xerUseUnion = xerattrib->useUnion_;
     sdef.xerUseTypeAttr  = xerattrib->useType_ || xerattrib->useUnion_;
-  }
+        }
   defUnionClass(&sdef, target);
   defUnionTemplate(&sdef, target);
 
diff --git a/compiler2/XSD_Types.cc b/compiler2/XSD_Types.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54be06573fc38729f93e03b3fe3cea6c47e3c8a6
--- /dev/null
+++ b/compiler2/XSD_Types.cc
@@ -0,0 +1,216 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Szabo, Bence Janos
+ *
+ ******************************************************************************/
+#include "XSD_Types.hh"
+#include <cstddef>
+#include "error.h"
+
+// Used in the code generation of the xer descriptor, and the union generation
+const char * XSD_type_to_string(const XSD_types xsd_type) {
+  switch (xsd_type) {
+    case XSD_NONE:
+      return "XSD_NONE";
+    case XSD_ANYSIMPLETYPE:
+      return "XSD_ANYSIMPLETYPE";
+    case XSD_ANYTYPE:
+      return "XSD_ANYTYPE";
+    case XSD_STRING:
+      return "XSD_STRING";
+    case XSD_NORMALIZEDSTRING:
+      return "XSD_NORMALIZEDSTRING";
+    case XSD_TOKEN:
+      return "XSD_TOKEN";
+    case XSD_NAME:
+      return "XSD_NAME";
+    case XSD_NMTOKEN:
+      return "XSD_NMTOKEN";
+    case XSD_NCName:
+      return "XSD_NCName";
+    case XSD_ID:
+      return "XSD_ID";
+    case XSD_IDREF:
+      return "XSD_IDREF";
+    case XSD_ENTITY:
+      return "XSD_ENTITY";
+    case XSD_HEXBINARY:
+      return "XSD_HEXBINARY";
+    case XSD_BASE64BINARY:
+      return "XSD_BASE64BINARY";
+    case XSD_ANYURI:
+      return "XSD_ANYURI";
+    case XSD_LANGUAGE:
+      return "XSD_LANGUAGE";
+    case XSD_INTEGER:
+      return "XSD_INTEGER";
+    case XSD_POSITIVEINTEGER:
+      return "XSD_POSITIVEINTEGER";
+    case XSD_NONPOSITIVEINTEGER:
+      return "XSD_NONPOSITIVEINTEGER";
+    case XSD_NEGATIVEINTEGER:
+      return "XSD_NEGATIVEINTEGER";
+    case XSD_NONNEGATIVEINTEGER:
+      return "XSD_NONNEGATIVEINTEGER";
+    case XSD_LONG:
+      return "XSD_LONG";
+    case XSD_UNSIGNEDLONG:
+      return "XSD_UNSIGNEDLONG";
+    case XSD_INT:
+      return "XSD_INT";
+    case XSD_UNSIGNEDINT:
+      return "XSD_UNSIGNEDINT";
+    case XSD_SHORT:
+      return "XSD_SHORT";
+    case XSD_UNSIGNEDSHORT:
+      return "XSD_UNSIGNEDSHORT";
+    case XSD_BYTE:
+      return "XSD_BYTE";
+    case XSD_UNSIGNEDBYTE:
+      return "XSD_UNSIGNEDBYTE";
+    case XSD_DECIMAL:
+      return "XSD_DECIMAL";
+    case XSD_FLOAT:
+      return "XSD_FLOAT";
+    case XSD_DOUBLE:
+      return "XSD_DOUBLE";
+    case XSD_DURATION:
+      return "XSD_DURATION";
+    case XSD_DATETIME:
+      return "XSD_DATETIME";
+    case XSD_TIME:
+      return "XSD_TIME";
+    case XSD_DATE:
+      return "XSD_DATE";
+    case XSD_GYEARMONTH:
+      return "XSD_GYEARMONTH";
+    case XSD_GYEAR:
+      return "XSD_GYEAR";
+    case XSD_GMONTHDAY:
+      return "XSD_GMONTHDAY";
+    case XSD_GDAY:
+      return "XSD_GDAY";
+    case XSD_GMONTH:
+      return "XSD_GMONTH";
+    case XSD_NMTOKENS:
+      return "XSD_NMTOKENS";
+    case XSD_IDREFS:
+      return "XSD_IDREFS";
+    case XSD_ENTITIES:
+      return "XSD_ENTITIES";
+    case XSD_QNAME:
+      return "XSD_QNAME";
+    case XSD_BOOLEAN:
+      return "XSD_BOOLEAN";
+    default:
+      FATAL_ERROR("XSD_Types::XSD_type_to_string - invalid XSD type");
+      return NULL;
+  }
+}
+
+// Used in the union XER encoder and decoder code generation
+const char * XSD_type_to_xml_type(const XSD_types xsd_type) {
+  switch (xsd_type) {
+    case XSD_NONE:
+      return "";
+    case XSD_ANYSIMPLETYPE:
+      return "anySimpleType";
+    case XSD_ANYTYPE:
+      return "anyType";
+    case XSD_STRING:
+      return "string";
+    case XSD_NORMALIZEDSTRING:
+      return "normalizedString";
+    case XSD_TOKEN:
+      return "token";
+    case XSD_NAME:
+      return "Name";
+    case XSD_NMTOKEN:
+      return "NMTOKEN";
+    case XSD_NCName:
+      return "NCName";
+    case XSD_ID:
+      return "ID";
+    case XSD_IDREF:
+      return "IDREF";
+    case XSD_ENTITY:
+      return "ENTITY";
+    case XSD_HEXBINARY:
+      return "hexBinary";
+    case XSD_BASE64BINARY:
+      return "base64Binary";
+    case XSD_ANYURI:
+      return "anyURI";
+    case XSD_LANGUAGE:
+      return "language";
+    case XSD_INTEGER:
+      return "integer";
+    case XSD_POSITIVEINTEGER:
+      return "positiveInteger";
+    case XSD_NONPOSITIVEINTEGER:
+      return "nonPositiveInteger";
+    case XSD_NEGATIVEINTEGER:
+      return "negativeInteger";
+    case XSD_NONNEGATIVEINTEGER:
+      return "nonNegativeInteger";
+    case XSD_LONG:
+      return "long";
+    case XSD_UNSIGNEDLONG:
+      return "unsignedLong";
+    case XSD_INT:
+      return "int";
+    case XSD_UNSIGNEDINT:
+      return "unsignedInt";
+    case XSD_SHORT:
+      return "short";
+    case XSD_UNSIGNEDSHORT:
+      return "unsignedShort";
+    case XSD_BYTE:
+      return "byte";
+    case XSD_UNSIGNEDBYTE:
+      return "unsignedByte";
+    case XSD_DECIMAL:
+      return "decimal";
+    case XSD_FLOAT:
+      return "float";
+    case XSD_DOUBLE:
+      return "double";
+    case XSD_DURATION:
+      return "duration";
+    case XSD_DATETIME:
+      return "dateTime";
+    case XSD_TIME:
+      return "time";
+    case XSD_DATE:
+      return "date";
+    case XSD_GYEARMONTH:
+      return "gYearMonth";
+    case XSD_GYEAR:
+      return "gYear";
+    case XSD_GMONTHDAY:
+      return "gMonthDay";
+    case XSD_GDAY:
+      return "gDay";
+    case XSD_GMONTH:
+      return "gMonth";
+    case XSD_NMTOKENS:
+      return "NMTOKENS";
+    case XSD_IDREFS:
+      return "IDREFS";
+    case XSD_ENTITIES:
+      return "ENTITIES";
+    case XSD_QNAME:
+      return "QName";
+    case XSD_BOOLEAN:
+      return "boolean";
+    default:
+      FATAL_ERROR("XSD_Types::XSD_type_to_xml_type - invalid XSD type");
+      return NULL;
+  }
+} 
\ No newline at end of file
diff --git a/compiler2/XSD_Types.hh b/compiler2/XSD_Types.hh
new file mode 100644
index 0000000000000000000000000000000000000000..00f2142ad041bd760870521845c9964e2856b497
--- /dev/null
+++ b/compiler2/XSD_Types.hh
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Szabo, Bence Janos
+ *
+ ******************************************************************************/
+#ifndef XSD_TYPES_HH_
+#define XSD_TYPES_HH_
+
+/**
+ * XSD type variants. For example: XSD:integer XSD:binary etc.
+ * A field can only have one of these variants.
+ * This enum should be in sync with the XSD_types enum in XER.hh
+ */
+typedef enum {
+  XSD_NONE = 0, // XER_NONE should be zero
+  XSD_ANYSIMPLETYPE, // Unused
+  XSD_ANYTYPE, // Unused
+  XSD_STRING,
+  XSD_NORMALIZEDSTRING,
+  XSD_TOKEN,
+  XSD_NAME,
+  XSD_NMTOKEN,
+  XSD_NCName,
+  XSD_ID,
+  XSD_IDREF,
+  XSD_ENTITY,
+  XSD_HEXBINARY,
+  XSD_BASE64BINARY,
+  XSD_ANYURI,
+  XSD_LANGUAGE,
+  XSD_INTEGER,
+  XSD_POSITIVEINTEGER,
+  XSD_NONPOSITIVEINTEGER,
+  XSD_NEGATIVEINTEGER,
+  XSD_NONNEGATIVEINTEGER,
+  XSD_LONG,
+  XSD_UNSIGNEDLONG,
+  XSD_INT,
+  XSD_UNSIGNEDINT,
+  XSD_SHORT,
+  XSD_UNSIGNEDSHORT,
+  XSD_BYTE,
+  XSD_UNSIGNEDBYTE,
+  XSD_DECIMAL,
+  XSD_FLOAT,
+  XSD_DOUBLE,
+  XSD_DURATION,
+  XSD_DATETIME,
+  XSD_TIME,
+  XSD_DATE,
+  XSD_GYEARMONTH,
+  XSD_GYEAR,
+  XSD_GMONTHDAY,
+  XSD_GDAY,
+  XSD_GMONTH,
+  XSD_NMTOKENS, // Unused
+  XSD_IDREFS, // Unused
+  XSD_ENTITIES, // Unused
+  XSD_QNAME, // Unused
+  XSD_BOOLEAN
+} XSD_types;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  
+const char * XSD_type_to_string(const XSD_types xsd_type);
+
+const char * XSD_type_to_xml_type(const XSD_types xsd_type);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+#endif /*XSD_TYPES_HH*/
\ No newline at end of file
diff --git a/compiler2/XerAttributes.cc b/compiler2/XerAttributes.cc
index 4e551f379e2c905e5aac71168bf5147cd84af5a4..ed40b446f48d0b3ca6ef3906437230d8643eb37f 100644
--- a/compiler2/XerAttributes.cc
+++ b/compiler2/XerAttributes.cc
@@ -62,6 +62,7 @@ XerAttributes::XerAttributes()
 , useType_(false)
 , useUnion_(false)
 , whitespace_(PRESERVE)
+, xsd_type(XSD_NONE)
 {
   //__asm("int3");
   //fprintf(stderr, "XER attributes(%p) new\n", (void*)this);
@@ -378,6 +379,10 @@ other.print("other");
   useType_ |= other.useType_;
   useUnion_ |= other.useUnion_;
   whitespace_ = other.whitespace_;
+
+  if (other.xsd_type != XSD_NONE) {
+    xsd_type = other.xsd_type;
+  }
   return *this;
 }
 
@@ -407,6 +412,7 @@ bool XerAttributes::empty() const
   && !useQName_
   && !useType_
   && !useUnion_
-  && whitespace_ == PRESERVE;
+  && whitespace_ == PRESERVE
+  && xsd_type == XSD_NONE;
 }
 
diff --git a/compiler2/XerAttributes.hh b/compiler2/XerAttributes.hh
index c6b44ae71e1139ca336435581b0681b818794b67..4ad64b2c0d7f8c90665a89d506f39d77a6ecd648 100644
--- a/compiler2/XerAttributes.hh
+++ b/compiler2/XerAttributes.hh
@@ -25,6 +25,7 @@
 #include <stddef.h>
 #include <limits.h>
 #include "../common/memory.h"
+#include "datatypes.h"
 
 namespace Common {
 class Value;
@@ -187,6 +188,7 @@ public:
   bool useType_;
   bool useUnion_;
   WhitespaceAction whitespace_;
+  XSD_types xsd_type;
 
   void print(const char *type_name) const;
 
diff --git a/compiler2/datatypes.h b/compiler2/datatypes.h
index 3de29a7d8821c7261435e49548a1b921f38e955b..91d719d98f05b710066592840aa2aea1b67744c2 100644
--- a/compiler2/datatypes.h
+++ b/compiler2/datatypes.h
@@ -15,6 +15,7 @@
  *   Raduly, Csaba
  *   Szabados, Kristof
  *   Szabo, Janos Zoltan – initial implementation
+ *   Szabo, Bence Janos
  *   Szalai, Gabor
  *
  ******************************************************************************/
@@ -23,6 +24,7 @@
 
 #include "asn1/asn1p_old.h"
 #include "ttcn3/rawASTspec.h"
+#include "XSD_Types.hh"
 /* Common types */
 
 typedef int boolean;
@@ -87,6 +89,7 @@ typedef struct {
   const char* jsonDefaultValue;
   /** true if the field is a record-of or set-of with optimized memory allocation */
   boolean optimizedMemAlloc;
+  XSD_types xsd_type;
 } struct_field;
 
 /** Structure (record, set, union, anytype) descriptor for code generation */
diff --git a/compiler2/ttcn3/rawAST.y b/compiler2/ttcn3/rawAST.y
index 514a43d295764bf600358e5325b3ca0810eee149..210fd9dcddc2d514993823275ea6754ab96ad1e8 100644
--- a/compiler2/ttcn3/rawAST.y
+++ b/compiler2/ttcn3/rawAST.y
@@ -10,6 +10,7 @@
  *   Baranyi, Botond
  *   Raduly, Csaba
  *   Szabo, Janos Zoltan – initial implementation
+ *   Szabo, Bence Janos
  *   Szalai, Gabor
  *   Zalanyi, Balazs Andor
  *
@@ -1502,60 +1503,64 @@ whiteSpace:
 xsddata: /* XSD:something */
     XSDbase64Binary {
       xerstruct->base64_ = true;
+      xerstruct->xsd_type = XSD_BASE64BINARY;
     }
     | XSDdecimal {
       xerstruct->decimal_ = true;
+      xerstruct->xsd_type = XSD_DECIMAL;
     }
     | XSDhexBinary {
       xerstruct->hex_ = true;
+      xerstruct->xsd_type = XSD_HEXBINARY;
     }
     | XSDQName {
       xerstruct->useQName_ = true;
+      xerstruct->xsd_type = XSD_QNAME;
     }
-    /* everything below is recognized and ignored */
-    | XKWshort {}
-    | XKWlong {}
-    | XSDstring           {}
-    | XSDnormalizedString {}
-    | XSDtoken            {}
-    | XSDName             {}
-    | XSDNMTOKEN          {}
-    | XSDNCName           {}
-    | XSDID               {}
-    | XSDIDREF            {}
-    | XSDENTITY           {}
-    | XSDanyURI           {}
-    | XSDlanguage         {}
+    /* everything below is recognized */
+    | XKWshort { xerstruct->xsd_type = XSD_SHORT; }
+    | XKWlong { xerstruct->xsd_type = XSD_LONG; }
+    | XSDstring           { xerstruct->xsd_type = XSD_STRING; }
+    | XSDnormalizedString { xerstruct->xsd_type = XSD_NORMALIZEDSTRING; }
+    | XSDtoken            { xerstruct->xsd_type = XSD_TOKEN; }
+    | XSDName             { xerstruct->xsd_type = XSD_NAME; }
+    | XSDNMTOKEN          { xerstruct->xsd_type = XSD_NMTOKEN; }
+    | XSDNCName           { xerstruct->xsd_type = XSD_NCName; }
+    | XSDID               { xerstruct->xsd_type = XSD_ID; }
+    | XSDIDREF            { xerstruct->xsd_type = XSD_IDREF; }
+    | XSDENTITY           { xerstruct->xsd_type = XSD_ENTITY; }
+    | XSDanyURI           { xerstruct->xsd_type = XSD_ANYURI; }
+    | XSDlanguage         { xerstruct->xsd_type = XSD_LANGUAGE; }
     /* TODO apply subtype to the types below */
-    | XSDinteger          {}
-    | XSDpositiveInteger  {}
-    | XSDnonPositiveInteger {}
-    | XSDnegativeInteger {}
-    | XSDnonNegativeInteger {}
-    | XSDunsignedLong     {}
-    | XSDint              {}
-    | XSDunsignedInt      {}
-    | XSDunsignedShort    {}
-    | XSDbyte             {}
-    | XSDunsignedByte     {}
-    | XSDfloat            {}
-    | XSDdouble           {}
-    | XSDduration         {}
-    | XSDdateTime         {}
-    | XSDtime             {}
-    | XSDdate             {}
-    | XSDgYearMonth       {}
-    | XSDgYear            {}
-    | XSDgMonthDay        {}
-    | XSDgDay             {}
-    | XSDgMonth           {}
-    | XSDNMTOKENS         {}
-    | XSDIDREFS           {}
-    | XSDENTITIES         {}
-    | XSDboolean          {}
-
-    | XSDanySimpleType    {}
-    | XSDanyType          {}
+    | XSDinteger          { xerstruct->xsd_type = XSD_INTEGER; }
+    | XSDpositiveInteger  { xerstruct->xsd_type = XSD_POSITIVEINTEGER; }
+    | XSDnonPositiveInteger { xerstruct->xsd_type = XSD_NONPOSITIVEINTEGER; }
+    | XSDnegativeInteger { xerstruct->xsd_type = XSD_NEGATIVEINTEGER; }
+    | XSDnonNegativeInteger { xerstruct->xsd_type = XSD_NONNEGATIVEINTEGER; }
+    | XSDunsignedLong     { xerstruct->xsd_type = XSD_UNSIGNEDLONG; }
+    | XSDint              { xerstruct->xsd_type = XSD_INT; }
+    | XSDunsignedInt      { xerstruct->xsd_type = XSD_UNSIGNEDINT; }
+    | XSDunsignedShort    { xerstruct->xsd_type = XSD_UNSIGNEDSHORT; }
+    | XSDbyte             { xerstruct->xsd_type = XSD_BYTE; }
+    | XSDunsignedByte     { xerstruct->xsd_type = XSD_UNSIGNEDBYTE; }
+    | XSDfloat            { xerstruct->xsd_type = XSD_FLOAT; }
+    | XSDdouble           { xerstruct->xsd_type = XSD_DOUBLE; }
+    | XSDduration         { xerstruct->xsd_type = XSD_DURATION; }
+    | XSDdateTime         { xerstruct->xsd_type = XSD_DATETIME; }
+    | XSDtime             { xerstruct->xsd_type = XSD_TIME; }
+    | XSDdate             { xerstruct->xsd_type = XSD_DATE; }
+    | XSDgYearMonth       { xerstruct->xsd_type = XSD_GYEARMONTH; }
+    | XSDgYear            { xerstruct->xsd_type = XSD_GYEAR; }
+    | XSDgMonthDay        { xerstruct->xsd_type = XSD_GMONTHDAY; }
+    | XSDgDay             { xerstruct->xsd_type = XSD_GDAY; }
+    | XSDgMonth           { xerstruct->xsd_type = XSD_GMONTH; }
+    | XSDNMTOKENS         { xerstruct->xsd_type = XSD_NMTOKENS; }
+    | XSDIDREFS           { xerstruct->xsd_type = XSD_IDREFS; }
+    | XSDENTITIES         { xerstruct->xsd_type = XSD_ENTITIES; }
+    | XSDboolean          { xerstruct->xsd_type = XSD_BOOLEAN; }
+
+    | XSDanySimpleType    { xerstruct->xsd_type = XSD_ANYSIMPLETYPE; }
+    | XSDanyType          { xerstruct->xsd_type = XSD_ANYTYPE; }
 
 ;
 
diff --git a/compiler2/union.c b/compiler2/union.c
index 42946acfa60aeab1d1c791ce52e4c641eda18fd3..b585ed8e5530300c8c748b997fbbb2e1483341b9 100644
--- a/compiler2/union.c
+++ b/compiler2/union.c
@@ -32,6 +32,7 @@
 #include "datatypes.h"
 #include "union.h"
 #include "encdec.h"
+#include "XSD_Types.hh"
 
 #include "main.hh"
 #include "ttcn3/compiler.h"
@@ -1374,9 +1375,11 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
         , sdef->elements[i].typegen
       );
       /* Type id attribute not needed for the first field in case of USE-TYPE */
+      // TODO: if USE-UNION there is no need to check the namelens
       if (sdef->xerUseUnion || i > 0) src = mputprintf(src,
-        "      need_type = (%s_xer_.namelens[1] > 2);\n"
-        , sdef->elements[i].typegen);
+          "      need_type = (%s_xer_.namelens[1] > 2) || %s_xer_.xsd_type != XSD_NONE;\n"
+          , sdef->elements[i].typegen
+          , sdef->elements[i].typegen);
       src = mputstr(src, "      break;\n");
     }
 
@@ -1423,6 +1426,26 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
     if (sdef->xerUseTypeAttr) {
       src = mputstr(src,
         "  const boolean e_xer = is_exer(p_flavor);\n"
+        "  boolean need_schema = FALSE;\n"
+        "  char *schema_prefix = mprintf(\"xsd\");\n"
+        "  int counter = 0;\n"
+        "  // Find a unique prefix for the xsd schema\n"
+        "  while (1) {\n"
+        "    boolean changed = FALSE;\n"
+        "    for (size_t i = 0; i < p_td.my_module->get_num_ns(); i++) {\n"
+        "      if (p_td.my_module->get_ns(i)->px != NULL &&\n"
+        "          strcmp(p_td.my_module->get_ns(i)->px, schema_prefix) == 0) {\n"
+        "        Free(schema_prefix);\n"
+        "        schema_prefix = mprintf(\"xsd%i\", counter);\n"
+        "        counter++;\n"
+        "        changed = TRUE;\n"
+        "        break; // new maybe unique prefix found\n"
+        "      }\n"
+        "    }\n"
+        "    if (!changed) {\n"
+        "      break; //break when a unique prefix found\n"
+        "    }\n"
+        "  }\n"
         "  char *type_atr = NULL;\n"
         "  if (e_xer && (p_td.xer_bits & USE_TYPE_ATTR)) {\n"
         "    char *type_name = 0;\n"
@@ -1433,29 +1456,44 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       for (i = start_at; i < sdef->nElements; i++) {
         src = mputprintf(src,
           "    case %s_%s:\n"
-          "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
-          "          %s_xer_.namelens[1] > 2) {\n"
-          /* add the namespace prefix to the type attribute (if the name is not empty) */
-          "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
-          "        if (my_ns->px[0] != 0) {\n"
-          "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
-          "        }\n"
-          "      }\n"
-          "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+          , selection_prefix, sdef->elements[i].name);
+        if (!sdef->xerUseUnion) { // UseType
+          src = mputprintf(src,
+            "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
+            "          %s_xer_.namelens[1] > 2) {\n"
+            /* add the namespace prefix to the type attribute (if the name is not empty) */
+            "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+            "        if (my_ns->px[0] != 0) {\n"
+            "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
+            "        }\n"
+            "      }\n"
+            "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
+            , sdef->elements[i].typegen);
+        }
+        if (sdef->elements[i].xsd_type != XSD_NONE) {
+          src = mputprintf(src,
+            "      if (type_name == NULL) {\n"
+            "        type_name = mputprintf(type_name, \"%%s:%s\", schema_prefix);\n"
+            "        need_schema = TRUE;\n"
+            "      }\n"
+            , XSD_type_to_xml_type(sdef->elements[i].xsd_type));
+        }
+        src = mputprintf(src,
           "      %s\n"
-          , selection_prefix, sdef->elements[i].name
-          , sdef->elements[i].typegen, sdef->elements[i].typegen
-          , sdef->elements[i].typegen, sdef->elements[i].typegen
-          , sdef->elements[i].typegen, sdef->elements[i].typegen
-          , sdef->elements[i].typegen
           , i < sdef->nElements - 1 ? "goto write_atr;" : "" /* no break */
         );
       }
       src = mputprintf(src,
         "%s" /* label only if more than two elements total */
-        "      if (mstrlen(type_name) > 0) {\n" /* 38.3.8, no atr if NAME AS "" */
+        "      if (mstrlen(type_name) > 0) {\n"
         "        control_ns = p_td.my_module->get_controlns();\n"
         "        type_atr = mcopystr(\" \");\n"
+        "        if (need_schema) {\n"
+        "          type_atr = mputprintf(type_atr, \"xmlns:%%s=\'http://www.w3.org/2001/XMLSchema\' \", schema_prefix);\n"
+        "        }\n"
         "        type_atr = mputstr(type_atr, control_ns->px);\n"
         "        type_atr = mputstr(type_atr, \":type='\");\n"
         "        type_atr = mputstr(type_atr, type_name);\n"
@@ -1466,6 +1504,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
         "    default: break;\n"
         "    }\n" /* switch */
         "  p_flavor &= ~XER_RECOF;\n"
+        "  Free(schema_prefix);\n"
         "  }\n" /* if e_xer */
         , (sdef->nElements > start_at + 1 ? "write_atr:\n" : "")
 
@@ -1529,6 +1568,26 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       if (sdef->xerUseTypeAttr) {
         src = mputstr(src,
           "  const boolean e_xer = is_exer(p_flavor);\n"
+          "  boolean need_schema = FALSE;\n"
+          "  char *schema_prefix = mprintf(\"xsd\");\n"
+          "  int counter = 0;\n"
+          "  // Find a unique prefix for the xsd schema\n"
+          "  while (1) {\n"
+          "    boolean changed = FALSE;\n"
+          "    for (size_t i = 0; i < p_td.my_module->get_num_ns(); i++) {\n"
+          "      if (p_td.my_module->get_ns(i)->px != NULL &&\n"
+          "          strcmp(p_td.my_module->get_ns(i)->px, schema_prefix) == 0) {\n"
+          "        Free(schema_prefix);\n"
+          "        schema_prefix = mprintf(\"xsd%i\", counter);\n"
+          "        counter++;\n"
+          "        changed = TRUE;\n"
+          "        break; // new maybe unique prefix found\n"
+          "      }\n"
+          "    }\n"
+          "    if (!changed) {\n"
+          "      break; //break when a unique prefix found\n"
+          "    }\n"
+          "  }\n"
           "  char *type_atr = NULL;\n"
           "  if (e_xer && (p_td.xer_bits & USE_TYPE_ATTR)) {\n"
           "    char *type_name = 0;\n"
@@ -1538,21 +1597,33 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
         for (i = start_at; i < sdef->nElements; i++) {
           src = mputprintf(src,
             "    case %s_%s:\n"
-            "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
-            "          %s_xer_.namelens[1] > 2) {\n"
-            /* add the namespace prefix to the type attribute (if the name is not empty) */
-            "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
-            "        if (my_ns->px[0] != 0) {\n"
-            "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
-            "        }\n"
-            "      }\n"
-            "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+            , selection_prefix, sdef->elements[i].name);
+          if (!sdef->xerUseUnion) { // UseType
+            src = mputprintf(src,
+              "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
+              "          %s_xer_.namelens[1] > 2) {\n"
+              /* add the namespace prefix to the type attribute (if the name is not empty) */
+              "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+              "        if (my_ns->px[0] != 0) {\n"
+              "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
+              "        }\n"
+              "      }\n"
+              "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+              , sdef->elements[i].typegen, sdef->elements[i].typegen
+              , sdef->elements[i].typegen, sdef->elements[i].typegen
+              , sdef->elements[i].typegen, sdef->elements[i].typegen
+              , sdef->elements[i].typegen);
+          }
+          if (sdef->elements[i].xsd_type != XSD_NONE) {
+            src = mputprintf(src,
+              "      if (type_name == NULL) {\n"
+              "        type_name = mputprintf(type_name, \"%%s:%s\", schema_prefix);\n"
+              "        need_schema = TRUE;\n"
+              "      }\n"
+              , XSD_type_to_xml_type(sdef->elements[i].xsd_type));
+          }
+          src = mputprintf(src,
             "      %s\n"
-            , selection_prefix, sdef->elements[i].name
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
-            , sdef->elements[i].typegen
             , i < sdef->nElements - 1 ? "goto write_atr;" : "" /* no break */
           );
         }
@@ -1561,6 +1632,9 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           "      if (mstrlen(type_name) > 0) {\n" /* 38.3.8, no atr if NAME AS "" */
           "        control_ns = p_td.my_module->get_controlns();\n"
           "        type_atr = mcopystr(\" \");\n"
+          "        if (need_schema) {\n"
+          "          type_atr = mputprintf(type_atr, \"xmlns:%%s=\'http://www.w3.org/2001/XMLSchema\' \", schema_prefix);\n"
+          "        }\n"
           "        type_atr = mputstr(type_atr, control_ns->px);\n"
           "        type_atr = mputstr(type_atr, \":type='\");\n"
           "        type_atr = mputstr(type_atr, type_name);\n"
@@ -1571,6 +1645,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           "    default: break;\n"
           "    }\n" /* switch */
           "  p_flavor &= ~XER_RECOF;\n"
+          "  Free(schema_prefix);\n"
           "  }\n" /* if e_xer */
           , (sdef->nElements > start_at + 1 ? "write_atr:\n" : "")
           );
@@ -1762,7 +1837,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
            *
            */
           "    if ((e_xer && (typeatr == NULL || !(p_td.xer_bits & USE_TYPE_ATTR))) "
-          "|| can_start(elem_name, ns_uri, %s_xer_, flavor_1)) {\n"
+          "|| can_start(elem_name, ns_uri, %s_xer_, flavor_1) || strcmp(elem_name, \"%s\") == 0) {\n"
           "      ec_2.set_msg(\"%s': \");\n"
           "      if (%s==union_selection) {\n"
           "        matched = %d;\n"
@@ -1771,6 +1846,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           "      if (field_%s->is_bound()) break; else clean_up();\n"
           "    }\n",
           sdef->elements[i].typegen,
+          XSD_type_to_xml_type(sdef->elements[i].xsd_type),
           sdef->elements[i].dispname,
           unbound_value, (int)i,
           sdef->elements[i].name,    sdef->elements[i].typegen,
@@ -1817,7 +1893,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       for (i = 0; i < sdef->nElements; i++) {
         if(sdef->exerMaybeEmptyIndex != i){
           src = mputprintf(src,
-            "    %sif (%s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT)) {\n"
+            "    %sif (%s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT) || strcmp(elem_name, \"%s\") == 0) {\n"
             "      ec_2.set_msg(\"%s': \");\n"
             "      if (e_xer && (%s_xer_.xer_bits & BLOCKED)) {\n"
             "        TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,\n"
@@ -1830,6 +1906,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
             "    }\n",
             i && !(i==1 && sdef->exerMaybeEmptyIndex==0) ? "else " : "",  /*  print "if(" if generate code for the first field or if the first field is the MaybeEmpty field and we generate the code for the second one*/
             sdef->elements[i].type, sdef->elements[i].typegen, sdef->elements[i].typegen,
+            XSD_type_to_xml_type(sdef->elements[i].xsd_type),
             sdef->elements[i].dispname,
             sdef->elements[i].typegen,
             at_field, sdef->elements[i].name,    sdef->elements[i].typegen,
@@ -1839,7 +1916,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       if(sdef->exerMaybeEmptyIndex>=0 ){
         i=sdef->exerMaybeEmptyIndex;
         src = mputprintf(src,
-          "    %sif ((e_xer && (type==XML_READER_TYPE_END_ELEMENT || !own_tag)) || %s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT)) {\n"
+          "    %sif ((e_xer && (type==XML_READER_TYPE_END_ELEMENT || !own_tag)) || %s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT) || strcmp(elem_name, \"%s\") == 0) {\n"
           "empty_xml:  ec_2.set_msg(\"%s': \");\n"
           "      if (e_xer && (%s_xer_.xer_bits & BLOCKED)) {\n"
           "        TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,\n"
@@ -1852,6 +1929,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           "    }\n",
           sdef->nElements>0 ? "else " : "",
           sdef->elements[i].type, sdef->elements[i].typegen, sdef->elements[i].typegen,
+          XSD_type_to_xml_type(sdef->elements[i].xsd_type),
           sdef->elements[i].dispname,
           sdef->elements[i].typegen,
           at_field, sdef->elements[i].name,    sdef->elements[i].typegen,
diff --git a/core/XER.hh b/core/XER.hh
index d78c2e94cba36830d0fd24f6e683edc883977fc1..1d2f6b71a0c883f5bffefe1580e17e28fe5a4dda 100644
--- a/core/XER.hh
+++ b/core/XER.hh
@@ -15,7 +15,7 @@
 #ifndef XER_HH_
 #define XER_HH_
 
-#include "Types.h"
+//#include "Types.h"
 #include "Encdec.hh"
 #include <stddef.h> // for size_t
 #include <string.h> // strncmp for the inline function
@@ -118,6 +118,60 @@ enum XER_whitespace_action {
   WHITESPACE_COLLAPSE
 };
 
+/**
+ * XSD type variants. For example: XSD:integer XSD:binary etc.
+ * A field can only have one of these variants.
+ * This enum should be in sync with the XSD_types enum in XSD_Types.hh
+ */
+typedef enum {
+  XSD_NONE = 0,
+  XSD_ANYSIMPLETYPE,
+  XSD_ANYTYPE,
+  XSD_STRING,
+  XSD_NORMALIZEDSTRING,
+  XSD_TOKEN,
+  XSD_NAME,
+  XSD_NMTOKEN,
+  XSD_NCName,
+  XSD_ID,
+  XSD_IDREF,
+  XSD_ENTITY,
+  XSD_HEXBINARY,
+  XSD_BASE64BINARY,
+  XSD_ANYURI,
+  XSD_LANGUAGE,
+  XSD_INTEGER,
+  XSD_POSITIVEINTEGER,
+  XSD_NONPOSITIVEINTEGER,
+  XSD_NEGATIVEINTEGER,
+  XSD_NONNEGATIVEINTEGER,
+  XSD_LONG,
+  XSD_UNSIGNEDLONG,
+  XSD_INT,
+  XSD_UNSIGNEDINT,
+  XSD_SHORT,
+  XSD_UNSIGNEDSHORT,
+  XSD_BYTE,
+  XSD_UNSIGNEDBYTE,
+  XSD_DECIMAL,
+  XSD_FLOAT,
+  XSD_DOUBLE,
+  XSD_DURATION,
+  XSD_DATETIME,
+  XSD_TIME,
+  XSD_DATE,
+  XSD_GYEARMONTH,
+  XSD_GYEAR,
+  XSD_GMONTHDAY,
+  XSD_GDAY,
+  XSD_GMONTH,
+  XSD_NMTOKENS,
+  XSD_IDREFS,
+  XSD_ENTITIES,
+  XSD_QNAME,
+  XSD_BOOLEAN
+} XSD_types;
+
 /// Check that \p f has the canonical flavor.
 inline bool is_canonical(unsigned int f)
 {
@@ -285,6 +339,9 @@ struct XERdescriptor_t
     * The -1 value is used to determine if fractionDigits encoding instruction is present,
     * so if the value is -1, no checks will be made. */
   const int fractionDigits;
+  
+  /** XSD type of field */
+  const XSD_types xsd_type;
 };
 
 /** Information related to the embedded values in XML encoding
@@ -454,7 +511,7 @@ void check_namespace_restrictions(const XERdescriptor_t& p_td, const char* p_xml
   extern const XERdescriptor_t type_name##_xer_ = { \
     { xmlname ">\n", xmlname ">\n" }, \
     { 2+sizeof(xmlname)-1, 2+sizeof(xmlname)-1 }, \
-    0UL, WHITESPACE_PRESERVE, NULL, NULL, 0, 0, NULL, NULL, -1 }
+    0UL, WHITESPACE_PRESERVE, NULL, NULL, 0, 0, NULL, NULL, -1, XSD_NONE }
 // The compiler should fold the two identical strings into one
 
 # define XER_STRUCT_COPY(cpy,original) \
diff --git a/regression_test/XML/EXER-whitepaper/UseUnion.ttcnpp b/regression_test/XML/EXER-whitepaper/UseUnion.ttcnpp
index 092b92d77323b4e2d1553dc37c7e43febde3fd71..bf455c093571052f3392fd0ee177e49ad44a6a09 100644
--- a/regression_test/XML/EXER-whitepaper/UseUnion.ttcnpp
+++ b/regression_test/XML/EXER-whitepaper/UseUnion.ttcnpp
@@ -26,6 +26,9 @@ type union ProductId {
 }
 with {
   variant "useUnion"
+  variant (c1) "XSD:integer";
+  variant (c2) "XSD:integer";
+  variant (c3) "XSD:integer";
 }
 
 type record ProductUU {
@@ -44,12 +47,18 @@ const ProductUU uuval := {
   color := "green"
 }
 
+const ProductUU uuval_decoded := {
+  id := { c1 := 100 },
+  price := 25.34,
+  color := "green"
+}
+
 DECLARE_XER_ENCODERS(ProductUU, uu);
 DECLARE_EXER_ENCODERS(ProductUU, uu);
 
 const universal charstring str_uu_e :=
 "<exm:ProductUU xmlns:exm=\'http://www.example.com\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
-"\t<id xsi:type=\'c2\'>100</id>\n" &
+"\t<id xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:integer'>100</id>\n" &
 "\t<price>25.340000</price>\n" &
 "\t<color>green</color>\n" &
 "</exm:ProductUU>\n" &
@@ -74,7 +83,7 @@ testcase encode_uu() runs on UU
 testcase decode_uu() runs on UU
 {
   CHECK_DECODE(bxer_dec_uu, str_uu_b, ProductUU, uuval);
-  CHECK_DECODE(exer_dec_uu, str_uu_e, ProductUU, uuval);
+  CHECK_DECODE(exer_dec_uu, str_uu_e, ProductUU, uuval_decoded); // 100 is decoded into c1
 }
 
 /* * * * * * * * HM81496 * * * * * * * * */
@@ -94,8 +103,10 @@ with {
   variant "useUnion";
   variant (integer_) "name as 'integer'";
   variant (boolean_) "name as 'boolean'";
+  variant (integer_) "XSD:integer";
   variant (boolean_) "text 'true' as '1'";
   variant (boolean_) "text 'false' as '0'";
+  variant (boolean_) "XSD:boolean";
 };
 
 DECLARE_XER_ENCODERS(E21named, e21n);
@@ -106,10 +117,10 @@ const E21named e21_b := { boolean_ := true }
 
 
 const universal charstring estr_e21_i :=
-"<E21named xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='integer'>1</E21named>\n\n";
+"<E21named xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:integer'>1</E21named>\n\n";
 
 const universal charstring estr_e21_b :=
-"<E21named xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='boolean'>1</E21named>\n\n";
+"<E21named xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:boolean'>1</E21named>\n\n";
 
 
 testcase encode_e21n() runs on UU
@@ -341,6 +352,14 @@ type union UUVal {
 } with {
   variant "name as 'UU'";
   variant "useUnion";
+  variant (i) "XSD:integer";
+  variant (b) "XSD:boolean";
+  variant (os) "XSD:hexBinary";
+  variant (hs) "XSD:token";
+  variant (f) "XSD:float";
+  variant (size) "XSD:string";
+  variant (cs) "XSD:normalizedString";
+  variant (ucs) "XSD:Name";
 }
 
 type record of UUVal UURec;
@@ -380,17 +399,17 @@ const UUList c_uu_list := {
 
 const universal charstring str_uu_rec :=
 "<UURec xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" &
-"\t<UU xsi:type='i'>19</UU>\n" &
-"\t<UU xsi:type='cs'>xyz</UU>\n" &
-"\t<UU xsi:type='size'>Small</UU>\n" &
-"\t<UU xsi:type='bs'>1101</UU>\n" &
-"\t<UU xsi:type='b'>true</UU>\n" &
-"\t<UU xsi:type='vt'>inconc</UU>\n" &
-"\t<UU xsi:type='f'>1.600000</UU>\n" &
-"\t<UU xsi:type='hs'>164FA</UU>\n" &
-"\t<UU xsi:type='os'>1BC6</UU>\n" &
-"\t<UU xsi:type='ucs'>ab" & char(0, 0, 1, 113) & "</UU>\n" &
-"\t<UU xsi:type='roi'>1 4 5 7 6 6 4</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:integer'>19</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:normalizedString'>xyz</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:string'>Small</UU>\n" &
+"\t<UU>1101</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:boolean'>true</UU>\n" &
+"\t<UU>inconc</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:float'>1.600000</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:token'>164FA</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:hexBinary'>1BC6</UU>\n" &
+"\t<UU xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:Name'>ab" & char(0, 0, 1, 113) & "</UU>\n" &
+"\t<UU>1 4 5 7 6 6 4</UU>\n" &
 "</UURec>\n\n";
 
 const universal charstring str_uu_list :=
diff --git a/regression_test/XML/Makefile b/regression_test/XML/Makefile
index d0433baeadea48fefd5a7eba09034e372aebaf78..d9b3c753b41549e82fb7691a853befec441f258a 100644
--- a/regression_test/XML/Makefile
+++ b/regression_test/XML/Makefile
@@ -30,7 +30,7 @@ endif
 XDIRS := $(wildcard $(SHADOWED)) xsdConverter \
 HM60295 HN15589 HQ30408 HR49727 HU13380 $(RT2_ONLY) \
 XmlWorkflow tpdValidTest AbstractBlock UseNilLong AttributeFormDefault \
-RecordOmit
+RecordOmit XSDBaseType
 
 # List of fake targets:
 .PHONY: all dep clean run $(XDIRS) $(addsuffix /, $(XDIRS)) profile
diff --git a/regression_test/XML/NegativeTest/exer_uni.ttcn b/regression_test/XML/NegativeTest/exer_uni.ttcn
index 6683ee09ff63df48d499b079ad8b03f08f76cb18..dd201858620869a05fa1ec03a009ce10f1d13fe5 100644
--- a/regression_test/XML/NegativeTest/exer_uni.ttcn
+++ b/regression_test/XML/NegativeTest/exer_uni.ttcn
@@ -254,6 +254,8 @@ type union UU
 }
 with {
   variant "useUnion";
+  variant (i) "XSD:integer";
+  variant (s) "XSD:string";
 }
 
 external function encUU(in UU u) return octetstring
@@ -269,8 +271,9 @@ template Nodes t_uu_i := {
   { XML_READER_TYPE_ELEMENT    , 0, "UU", "", "" },
   { XML_READER_TYPE_ATTRIBUTE  , 1, "xmlns:xsi",      "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
   // this is the value     for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+  { XML_READER_TYPE_ATTRIBUTE  , 1, "xmlns:xsd",      "http://www.w3.org/2001/XMLSchema",          "http://www.w3.org/2000/xmlns/" },
   // this is the namespace for "xsi:type"  ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
-  { XML_READER_TYPE_ATTRIBUTE  , 1, "xsi:type" , "i", "http://www.w3.org/2001/XMLSchema-instance" },
+  { XML_READER_TYPE_ATTRIBUTE  , 1, "xsi:type" , "xsd:integer", "http://www.w3.org/2001/XMLSchema-instance" },
   { XML_READER_TYPE_TEXT       , 1, "#text", "42", "" },
   { XML_READER_TYPE_END_ELEMENT, 0, "UU", "", "" }
 }
@@ -284,8 +287,9 @@ template Nodes t_uu_s := {
   { XML_READER_TYPE_ELEMENT    , 0, "UU", "", "" },
   { XML_READER_TYPE_ATTRIBUTE  , 1, "xmlns:xsi",      "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
   // this is the value     for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+  { XML_READER_TYPE_ATTRIBUTE  , 1, "xmlns:xsd",      "http://www.w3.org/2001/XMLSchema",          "http://www.w3.org/2000/xmlns/" },
   // this is the namespace for "xsi:type"  ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
-  { XML_READER_TYPE_ATTRIBUTE  , 1, "xsi:type" , "s", "http://www.w3.org/2001/XMLSchema-instance" },
+  { XML_READER_TYPE_ATTRIBUTE  , 1, "xsi:type" , "xsd:string", "http://www.w3.org/2001/XMLSchema-instance" },
   { XML_READER_TYPE_TEXT       , 1, "#text", "Hello, world!", "" },
   { XML_READER_TYPE_END_ELEMENT, 0, "UU", "", "" }
 }
diff --git a/regression_test/XML/NegativeTest/runner.ttcn b/regression_test/XML/NegativeTest/runner.ttcn
index aaf06db13f7b04450081d965b26fe11861c1cdfc..99744f8c4682ecb0db6504d766bce489e82ccc6c 100644
--- a/regression_test/XML/NegativeTest/runner.ttcn
+++ b/regression_test/XML/NegativeTest/runner.ttcn
@@ -48,7 +48,7 @@ control // the only control part in the system
   execute(u_replace());
   execute(u_before_embedded());
 
-  // testcases imporeted from exer_rec_of
+  // testcases imported from exer_rec_of
   execute(exer_recof_plain());
   execute(exer_recof_before0());
 
diff --git a/regression_test/XML/TTCNandXML/X693amd1.ttcn b/regression_test/XML/TTCNandXML/X693amd1.ttcn
index 554b4bd50172504868317d2ad680781abc916528..b9479dafaec3c3096708e7dfab579cc0aacd98e8 100644
--- a/regression_test/XML/TTCNandXML/X693amd1.ttcn
+++ b/regression_test/XML/TTCNandXML/X693amd1.ttcn
@@ -38,7 +38,9 @@ type union Int_or_boolean_u {
 }
 with {
   variant "useUnion";
-  variant (boolean_) "name as 'boolean'"
+  variant (int) "XSD:integer";
+  variant (boolean_) "name as 'boolean'";
+  variant (boolean_) "XSD:boolean";
 }
 
 //---------- C.3.2  USE-TYPE
diff --git a/regression_test/XML/TTCNandXML/X693amd1Test.ttcnpp b/regression_test/XML/TTCNandXML/X693amd1Test.ttcnpp
index c8a93577c60a7b6c936c74dbb7f60b9aafed02c8..67aaa8f73e60921ad0f2ea15938ee38af9e9d2a4 100644
--- a/regression_test/XML/TTCNandXML/X693amd1Test.ttcnpp
+++ b/regression_test/XML/TTCNandXML/X693amd1Test.ttcnpp
@@ -88,7 +88,7 @@ const universal charstring str_39_b :=
 "</Int_or_boolean_u>\n\n";
 
 const universal charstring str_39_e :=
-"<Int_or_boolean_u xmlns:p='cns' p:type='int'>39</Int_or_boolean_u>\n\n";
+"<Int_or_boolean_u xmlns:p='cns' xmlns:xsd='http://www.w3.org/2001/XMLSchema' p:type='xsd:integer'>39</Int_or_boolean_u>\n\n";
 
 // Second alternative (bool)
 const Int_or_boolean_u so_true := { boolean_ := true };
@@ -99,7 +99,7 @@ const universal charstring str_true_b :=
 "</Int_or_boolean_u>\n\n";
 
 const universal charstring str_true_e :=
-"<Int_or_boolean_u xmlns:p='cns' p:type='boolean'>true</Int_or_boolean_u>\n\n";
+"<Int_or_boolean_u xmlns:p='cns' xmlns:xsd='http://www.w3.org/2001/XMLSchema' p:type='xsd:boolean'>true</Int_or_boolean_u>\n\n";
 
 
 testcase enc_uu() runs on ice
diff --git a/regression_test/XML/XSDBaseType/Makefile b/regression_test/XML/XSDBaseType/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ad920c4a175a4c24e294962ac868ab95260af5ec
--- /dev/null
+++ b/regression_test/XML/XSDBaseType/Makefile
@@ -0,0 +1,150 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR = ../..
+include  ../../Makefile.regression
+
+# WARNING! This Makefile can be used with GNU make only.
+# Other versions of make may report syntax errors in it.
+
+#
+# Do NOT touch this line...
+#
+.PHONY: all archive check clean dep objects
+
+.SUFFIXES: .d
+
+#
+# Set these variables...
+#
+
+# Flags for the C++ preprocessor (and makedepend as well):
+#CPPFLAGS +=
+
+# Flags for dependency generation
+CXXDEPFLAGS = -MM
+
+# Flags for the C++ compiler:
+CXXFLAGS += -Wall
+
+# Flags for the linker:
+#LDFLAGS += 
+
+# Flags for the TTCN-3 and ASN.1 compiler:
+#COMPILER_FLAGS +=  
+
+# Execution mode: (either ttcn3 or ttcn3-parallel)
+TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
+
+#
+# You may change these variables. Add your files if necessary...
+#
+
+# TTCN-3 modules of this project:
+TTCN3_MODULES = XSDBaseTypeTest.ttcn schema.ttcn XSD.ttcn UsefulTtcn3Types.ttcn
+
+# ASN.1 modules of this project:
+ASN1_MODULES =
+
+# C++ source & header files generated from the TTCN-3 & ASN.1 modules of
+# this project:
+GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) $(ASN1_MODULES:.asn=.cc)
+GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
+ifdef SPLIT_TO_SLICES
+POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_))
+POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc))
+GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES)))
+GENERATED_SOURCES += $(GENERATED_SOURCES2)
+endif
+# C/C++ Source & header files of Test Ports, external functions and
+# other modules:
+USER_SOURCES =
+USER_HEADERS = $(USER_SOURCES:.cc=.hh)
+
+# Object files of this project that are needed for the executable test suite:
+OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)
+
+GENERATED_OBJECTS = $(GENERATED_SOURCES:.cc=.o)
+
+USER_OBJECTS = $(USER_SOURCES:.cc=.o)
+
+DEPFILES = $(USER_OBJECTS:.o=.d)  $(GENERATED_OBJECTS:.o=.d)
+
+# Other files of the project (Makefile, configuration files, etc.)
+# that will be added to the archived source files:
+OTHER_FILES = Makefile
+
+# The name of the executable test suite:
+TARGET = XSDBaseTypeTest
+
+#
+# Rules for building the executable...
+#
+
+all: $(TARGET) ;
+
+objects: $(OBJECTS) compile;
+
+$(TARGET): $(OBJECTS)
+	if $(CXX) $(LDFLAGS) -o $@ $^ \
+	-L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
+	-L$(OPENSSL_DIR)/lib -lcrypto \
+	-L$(XMLDIR)/lib $($(PLATFORM)_LIBS); \
+	then : ; else $(TTCN3_DIR)/bin/titanver $(OBJECTS); exit 1; fi
+
+.cc.o .c.o:
+	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
+
+.cc.d .c.d:
+	@echo Creating dependency file for '$<'; set -e; \
+	$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \
+	| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
+	[ -s $@ ] || rm -f $@
+
+$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile
+	@if [ ! -f $@ ]; then $(RM) compile; $(MAKE) compile; fi
+
+compile: $(TTCN3_MODULES) $(ASN1_MODULES)
+	$(TTCN3_COMPILER) $(COMPILER_FLAGS) $^ - $?
+	touch $@
+
+XSD.ttcn UsefulTtcn3Types.ttcn:
+	$(TTCN3_DIR)/bin/xsd2ttcn -m
+
+clean distclean:
+	-$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
+	$(GENERATED_SOURCES) compile $(DEPFILES) XSD.ttcn UsefulTtcn3Types.ttcn \
+	tags *.log
+
+dep: $(GENERATED_SOURCES) $(USER_SOURCES) ;
+
+ifeq ($(findstring n,$(MAKEFLAGS)),)
+ifeq ($(filter clean distclean check compile archive diag,$(MAKECMDGOALS)),)
+-include $(DEPFILES)
+endif
+endif
+
+diag:
+	$(TTCN3_COMPILER) -v 2>&1
+	$(TTCN3_DIR)/bin/mctr_cli -v 2>&1
+	$(CXX) -v 2>&1
+	@echo TTCN3_DIR=$(TTCN3_DIR)
+	@echo OPENSSL_DIR=$(OPENSSL_DIR)
+	@echo XMLDIR=$(XMLDIR)
+	@echo PLATFORM=$(PLATFORM)
+
+#
+# Add your rules here if necessary...
+#
+
+run: $(TARGET)
+	./$^
+
diff --git a/regression_test/XML/XSDBaseType/XSDBaseTypeTest.ttcn b/regression_test/XML/XSDBaseType/XSDBaseTypeTest.ttcn
new file mode 100644
index 0000000000000000000000000000000000000000..f08a14ac2ac9588dde40a6b2236c8d8eae3861d5
--- /dev/null
+++ b/regression_test/XML/XSDBaseType/XSDBaseTypeTest.ttcn
@@ -0,0 +1,1222 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Szabo, Bence Janos
+ *
+ ******************************************************************************/
+module XSDBaseTypeTest {
+
+    import from schema all;
+
+    external function enc_UnnamedType(in UnnamedType pdu) return octetstring
+     with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }
+  
+    external function dec_UnnamedType(in octetstring stream) return UnnamedType
+     with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }
+
+    external function enc_NamedType(in NamedType pdu) return octetstring
+     with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }
+  
+    external function dec_NamedType(in octetstring stream) return NamedType
+     with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }
+
+    external function enc_UseTypeWithUseUnion(in UseTypeWithUseUnion pdu) return octetstring
+     with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }
+  
+    external function dec_UseTypeWithUseUnion(in octetstring stream) return UseTypeWithUseUnion
+     with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }
+
+    external function enc_UseUnionWithoutXSDType(in UseUnionWithoutXSDType pdu) return octetstring
+     with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }
+  
+    external function dec_UseUnionWithoutXSDType(in octetstring stream) return UseUnionWithoutXSDType
+     with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }
+ 
+    type component C {}
+
+///////////////////////////////////////////////////////////////////////////////
+
+// All expected encoding result of the UnnamedType's fields.
+
+    const charstring string_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:string'>string</xsd:UnnamedType>\n\n";
+    const charstring normalizedstring_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:normalizedString'>normalizedstring</xsd:UnnamedType>\n\n";
+    const charstring token_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:token'>token</xsd:UnnamedType>\n\n";
+    const charstring name_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:Name'>name</xsd:UnnamedType>\n\n";
+    const charstring nmtoken_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:NMTOKEN'>nmtoken</xsd:UnnamedType>\n\n";
+    const charstring ncname_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:NCName'>ncname</xsd:UnnamedType>\n\n";
+    const charstring id_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:ID'>id</xsd:UnnamedType>\n\n";
+    const charstring idref_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:IDREF'>idref</xsd:UnnamedType>\n\n";
+    const charstring entity_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:ENTITY'>entity</xsd:UnnamedType>\n\n";
+    const charstring hexbinary_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:hexBinary'>AABBCCDD</xsd:UnnamedType>\n\n";
+    const charstring base64binary_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:base64Binary'>qrvM3Q==</xsd:UnnamedType>\n\n";
+    const charstring anyuri_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:anyURI'>www.any.uri</xsd:UnnamedType>\n\n";
+    const charstring language_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:language'>hun</xsd:UnnamedType>\n\n";
+    const charstring integer_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:integer'>13</xsd:UnnamedType>\n\n";
+    const charstring positiveinteger_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:positiveInteger'>14</xsd:UnnamedType>\n\n";
+    const charstring nonpositiveinteger_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:nonPositiveInteger'>-15</xsd:UnnamedType>\n\n";
+    const charstring negativeinteger_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:negativeInteger'>-16</xsd:UnnamedType>\n\n";
+    const charstring nonnegativeinteger_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:nonNegativeInteger'>17</xsd:UnnamedType>\n\n";
+    const charstring long_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:long'>18</xsd:UnnamedType>\n\n";
+    const charstring unsignedlong_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedLong'>19</xsd:UnnamedType>\n\n";
+    const charstring int_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:int'>20</xsd:UnnamedType>\n\n";
+    const charstring unsignedint_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedInt'>21</xsd:UnnamedType>\n\n";
+    const charstring short_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:short'>22</xsd:UnnamedType>\n\n";
+    const charstring unsignedshort_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedShort'>23</xsd:UnnamedType>\n\n";
+    const charstring byte_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:byte'>24</xsd:UnnamedType>\n\n";
+    const charstring unsignedbyte_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedByte'>25</xsd:UnnamedType>\n\n";
+    const charstring decimal_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:decimal'>26.000000</xsd:UnnamedType>\n\n";
+    const charstring float_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:float'>27.000000</xsd:UnnamedType>\n\n";
+    const charstring double_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:double'>28.000000</xsd:UnnamedType>\n\n";
+    const charstring duration_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:duration'>P5Y2M10D</xsd:UnnamedType>\n\n";
+    const charstring datetime_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:dateTime'>2002-05-30T09:30:10</xsd:UnnamedType>\n\n";
+    const charstring time_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:time'>09:30:10</xsd:UnnamedType>\n\n";
+    const charstring date_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:date'>2002-05-30</xsd:UnnamedType>\n\n";
+    const charstring gyearmonth_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gYearMonth'>2002-05</xsd:UnnamedType>\n\n";
+    const charstring gyear_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gYear'>2002</xsd:UnnamedType>\n\n";
+    const charstring gmonthday_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gMonthDay'>--11-11</xsd:UnnamedType>\n\n";
+    const charstring gday_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gDay'>---11</xsd:UnnamedType>\n\n";
+    const charstring gmonth_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gMonth'>--11</xsd:UnnamedType>\n\n";
+    const charstring boolean_result := "<xsd:UnnamedType xmlns:xsd='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:boolean'>true</xsd:UnnamedType>\n\n";
+
+    testcase tc_unnamed() runs on C system C {
+
+      // string
+      var UnnamedType my_type := { alt_ := "string" }
+      var UnnamedType my_type_result;
+
+      var octetstring result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), string_result) == false) {
+        setverdict(fail, match(oct2unichar(result), string_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // normalizedString
+      my_type := { alt_1 := "normalizedstring" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), normalizedstring_result) == false) {
+        setverdict(fail, match(oct2unichar(result), normalizedstring_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // token
+      my_type := { alt_2 := "token" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), token_result) == false) {
+        setverdict(fail, match(oct2unichar(result), token_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // Name
+      my_type := { alt_3 := "name" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), name_result) == false) {
+        setverdict(fail, match(oct2unichar(result), name_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // NMTOKEN
+      my_type := { alt_4 := "nmtoken" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), nmtoken_result) == false) {
+        setverdict(fail, match(oct2unichar(result), nmtoken_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // NCName
+      my_type := { alt_5 := "ncname" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), ncname_result) == false) {
+        setverdict(fail, match(oct2unichar(result), ncname_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // ID
+      my_type := { alt_6 := "id" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), id_result) == false) {
+        setverdict(fail, match(oct2unichar(result), id_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // IDREF
+      my_type := { alt_7 := "idref" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), idref_result) == false) {
+        setverdict(fail, match(oct2unichar(result), idref_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // ENTITY
+      my_type := { alt_8 := "entity" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), entity_result) == false) {
+        setverdict(fail, match(oct2unichar(result), entity_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // hexBinary
+      my_type := { alt_9 := 'AABBCCDD'O }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), hexbinary_result) == false) {
+        setverdict(fail, match(oct2unichar(result), hexbinary_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // base64Binary
+      my_type := { alt_10 := 'AABBCCDD'O }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), base64binary_result) == false) {
+        setverdict(fail, match(oct2unichar(result), base64binary_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // anyURI
+      my_type := { alt_11 := "www.any.uri" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), anyuri_result) == false) {
+        setverdict(fail, match(oct2unichar(result), anyuri_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // language
+      my_type := { alt_12 := "hun" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), language_result) == false) {
+        setverdict(fail, match(oct2unichar(result), language_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // integer
+      my_type := { alt_13 := 13 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), integer_result) == false) {
+        setverdict(fail, match(oct2unichar(result), integer_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // positiveInteger
+      my_type := { alt_14 := 14 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), positiveinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), positiveinteger_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // nonPositiveInteger
+      my_type := { alt_15 := -15 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), nonpositiveinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), nonpositiveinteger_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // negativeInteger
+      my_type := { alt_16 := -16 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), negativeinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), negativeinteger_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // nonNegativeInteger
+      my_type := { alt_17 := 17 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), nonnegativeinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), nonnegativeinteger_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // long
+      my_type := { alt_18 := 18 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), long_result) == false) {
+        setverdict(fail, match(oct2unichar(result), long_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedLong
+      my_type := { alt_19 := 19 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), unsignedlong_result) == false) {
+        setverdict(fail, match(oct2unichar(result), unsignedlong_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // int
+      my_type := { alt_20 := 20 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), int_result) == false) {
+        setverdict(fail, match(oct2unichar(result), int_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedInt
+      my_type := { alt_21 := 21 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), unsignedint_result) == false) {
+        setverdict(fail, match(oct2unichar(result), unsignedint_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // short
+      my_type := { alt_22 := 22 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), short_result) == false) {
+        setverdict(fail, match(oct2unichar(result), short_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedShort
+      my_type := { alt_23 := 23 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), unsignedshort_result) == false) {
+        setverdict(fail, match(oct2unichar(result), unsignedshort_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // byte
+      my_type := { alt_24 := 24 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), byte_result) == false) {
+        setverdict(fail, match(oct2unichar(result), byte_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedByte
+      my_type := { alt_25 := 25 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), unsignedbyte_result) == false) {
+        setverdict(fail, match(oct2unichar(result), unsignedbyte_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // decimal
+      my_type := { alt_26 := 26.0 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), decimal_result) == false) {
+        setverdict(fail, match(oct2unichar(result), decimal_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // float
+      my_type := { alt_27 := 27.0 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), float_result) == false) {
+        setverdict(fail, match(oct2unichar(result), float_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // double
+      my_type := { alt_28 := 28.0 }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), double_result) == false) {
+        setverdict(fail, match(oct2unichar(result), double_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // duration
+      my_type := { alt_29 := "P5Y2M10D" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), duration_result) == false) {
+        setverdict(fail, match(oct2unichar(result), duration_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // dateTime
+      my_type := { alt_30 := "2002-05-30T09:30:10" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), datetime_result) == false) {
+        setverdict(fail, match(oct2unichar(result), datetime_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // time
+      my_type := { alt_31 := "09:30:10" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), time_result) == false) {
+        setverdict(fail, match(oct2unichar(result), time_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // date
+      my_type := { alt_32 := "2002-05-30" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), date_result) == false) {
+        setverdict(fail, match(oct2unichar(result), date_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gYearMonth
+      my_type := { alt_33 := "2002-05" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), gyearmonth_result) == false) {
+        setverdict(fail, match(oct2unichar(result), gyearmonth_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gYear
+      my_type := { alt_34 := "2002" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), gyear_result) == false) {
+        setverdict(fail, match(oct2unichar(result), gyear_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gMonthDay
+      my_type := { alt_35 := "--11-11" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), gmonthday_result) == false) {
+        setverdict(fail, match(oct2unichar(result), gmonthday_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gDay
+      my_type := { alt_36 := "---11" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), gday_result) == false) {
+        setverdict(fail, match(oct2unichar(result), gday_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gMonth
+      my_type := { alt_37 := "--11" }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), gmonth_result) == false) {
+        setverdict(fail, match(oct2unichar(result), gmonth_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // boolean
+      my_type := { alt_38 := true }
+
+      result := enc_UnnamedType(my_type);
+      if (match(oct2unichar(result), boolean_result) == false) {
+        setverdict(fail, match(oct2unichar(result), boolean_result));
+      }
+      my_type_result := dec_UnnamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+      
+      setverdict(pass);
+    }
+
+///////////////////////////////////////////////////////////////////////////////
+
+// All expected encoding result of the NamedType's fields.
+
+    const charstring named_string_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:string'>string</xsd0:NamedType>\n\n";
+    const charstring named_normalizedstring_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:normalizedString'>normalizedstring</xsd0:NamedType>\n\n";
+    const charstring named_token_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:token'>token</xsd0:NamedType>\n\n";
+    const charstring named_name_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:Name'>name</xsd0:NamedType>\n\n";
+    const charstring named_nmtoken_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:NMTOKEN'>nmtoken</xsd0:NamedType>\n\n";
+    const charstring named_ncname_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:NCName'>ncname</xsd0:NamedType>\n\n";
+    const charstring named_id_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:ID'>id</xsd0:NamedType>\n\n";
+    const charstring named_idref_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:IDREF'>idref</xsd0:NamedType>\n\n";
+    const charstring named_entity_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:ENTITY'>entity</xsd0:NamedType>\n\n";
+    const charstring named_hexbinary_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:hexBinary'>AABBCCDD</xsd0:NamedType>\n\n";
+    const charstring named_base64binary_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:base64Binary'>qrvM3Q==</xsd0:NamedType>\n\n";
+    const charstring named_anyuri_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:anyURI'>www.any.uri</xsd0:NamedType>\n\n";
+    const charstring named_language_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:language'>hun</xsd0:NamedType>\n\n";
+    const charstring named_integer_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:integer'>13</xsd0:NamedType>\n\n";
+    const charstring named_positiveinteger_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:positiveInteger'>14</xsd0:NamedType>\n\n";
+    const charstring named_nonpositiveinteger_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:nonPositiveInteger'>-15</xsd0:NamedType>\n\n";
+    const charstring named_negativeinteger_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:negativeInteger'>-16</xsd0:NamedType>\n\n";
+    const charstring named_nonnegativeinteger_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:nonNegativeInteger'>17</xsd0:NamedType>\n\n";
+    const charstring named_long_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:long'>18</xsd0:NamedType>\n\n";
+    const charstring named_unsignedlong_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedLong'>19</xsd0:NamedType>\n\n";
+    const charstring named_int_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:int'>20</xsd0:NamedType>\n\n";
+    const charstring named_unsignedint_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedInt'>21</xsd0:NamedType>\n\n";
+    const charstring named_short_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:short'>22</xsd0:NamedType>\n\n";
+    const charstring named_unsignedshort_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedShort'>23</xsd0:NamedType>\n\n";
+    const charstring named_byte_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:byte'>24</xsd0:NamedType>\n\n";
+    const charstring named_unsignedbyte_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:unsignedByte'>25</xsd0:NamedType>\n\n";
+    const charstring named_decimal_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:decimal'>26.000000</xsd0:NamedType>\n\n";
+    const charstring named_float_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:float'>27.000000</xsd0:NamedType>\n\n";
+    const charstring named_double_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:double'>28.000000</xsd0:NamedType>\n\n";
+    const charstring named_duration_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:duration'>P5Y2M10D</xsd0:NamedType>\n\n";
+    const charstring named_datetime_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:dateTime'>2002-05-30T09:30:10</xsd0:NamedType>\n\n";
+    const charstring named_time_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:time'>09:30:10</xsd0:NamedType>\n\n";
+    const charstring named_date_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:date'>2002-05-30</xsd0:NamedType>\n\n";
+    const charstring named_gyearmonth_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gYearMonth'>2002-05</xsd0:NamedType>\n\n";
+    const charstring named_gyear_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gYear'>2002</xsd0:NamedType>\n\n";
+    const charstring named_gmonthday_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gMonthDay'>--11-11</xsd0:NamedType>\n\n";
+    const charstring named_gday_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gDay'>---11</xsd0:NamedType>\n\n";
+    const charstring named_gmonth_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:gMonth'>--11</xsd0:NamedType>\n\n";
+    const charstring named_boolean_result := "<xsd0:NamedType xmlns:xsd0='schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:boolean'>true</xsd0:NamedType>\n\n";
+
+
+    testcase tc_named() runs on C system C {
+
+      // string
+      var NamedType my_type := { string := "string" }
+      var NamedType my_type_result;
+
+      var octetstring result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_string_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_string_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // normalizedString
+      my_type := { normalizedString := "normalizedstring" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_normalizedstring_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_normalizedstring_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // token
+      my_type := { token := "token" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_token_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_token_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // Name
+      my_type := { name := "name" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_name_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_name_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // NMTOKEN
+      my_type := { nMTOKEN := "nmtoken" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_nmtoken_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_nmtoken_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // NCName
+      my_type := { nCName := "ncname" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_ncname_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_ncname_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // ID
+      my_type := { iD := "id" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_id_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_id_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // IDREF
+      my_type := { iDREF := "idref" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_idref_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_idref_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // ENTITY
+      my_type := { eNTITY := "entity" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_entity_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_entity_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // hexBinary
+      my_type := { hexBinary := 'AABBCCDD'O }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_hexbinary_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_hexbinary_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // base64Binary
+      my_type := { base64Binary := 'AABBCCDD'O }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_base64binary_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_base64binary_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // anyURI
+      my_type := { anyURI := "www.any.uri" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_anyuri_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_anyuri_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // language
+      my_type := { language_ := "hun" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_language_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_language_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // integer
+      my_type := { integer_ := 13 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_integer_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_integer_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // positiveInteger
+      my_type := { positiveInteger := 14 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_positiveinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_positiveinteger_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // nonPositiveInteger
+      my_type := { nonPositiveInteger := -15 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_nonpositiveinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_nonpositiveinteger_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // negativeInteger
+      my_type := { negativeInteger := -16 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_negativeinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_negativeinteger_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // nonNegativeInteger
+      my_type := { nonNegativeInteger := 17 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_nonnegativeinteger_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_nonnegativeinteger_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // long
+      my_type := { long := 18 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_long_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_long_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedLong
+      my_type := { unsignedLong := 19 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_unsignedlong_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_unsignedlong_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // int
+      my_type := { int := 20 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_int_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_int_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedInt
+      my_type := { unsignedInt := 21 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_unsignedint_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_unsignedint_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // short
+      my_type := { short := 22 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_short_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_short_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedShort
+      my_type := { unsignedShort := 23 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_unsignedshort_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_unsignedshort_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // byte
+      my_type := { byte := 24 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_byte_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_byte_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // unsignedByte
+      my_type := { unsignedByte := 25 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_unsignedbyte_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_unsignedbyte_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // decimal
+      my_type := { decimal := 26.0 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_decimal_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_decimal_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // float
+      my_type := { float_ := 27.0 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_float_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_float_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // double
+      my_type := { double := 28.0 }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_double_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_double_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // duration
+      my_type := { duration := "P5Y2M10D" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_duration_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_duration_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // dateTime
+      my_type := { dateTime := "2002-05-30T09:30:10" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_datetime_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_datetime_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // time
+      my_type := { time := "09:30:10" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_time_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_time_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // date
+      my_type := { date := "2002-05-30" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_date_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_date_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gYearMonth
+      my_type := { gYearMonth := "2002-05" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_gyearmonth_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_gyearmonth_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gYear
+      my_type := { gYear := "2002" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_gyear_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_gyear_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gMonthDay
+      my_type := { gMonthDay := "--11-11" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_gmonthday_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_gmonthday_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gDay
+      my_type := { gDay := "---11" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_gday_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_gday_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // gMonth
+      my_type := { gMonth := "--11" }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_gmonth_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_gmonth_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // boolean
+      my_type := { boolean_ := true }
+
+      result := enc_NamedType(my_type);
+      if (match(oct2unichar(result), named_boolean_result) == false) {
+        setverdict(fail, match(oct2unichar(result), named_boolean_result));
+      }
+      my_type_result := dec_NamedType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+      
+      setverdict(pass);
+    }
+
+///////////////////////////////////////////////////////////////////////////////
+
+    type union TypeWithUseUnion {
+      charstring cs,
+      octetstring os
+    } with {
+      encode "XML";
+      variant "useUnion";
+      variant (cs) "XSD:string";
+      variant (os) "XSD:hexBinary";
+    }
+
+    type union UseTypeWithUseUnion {
+      boolean b,
+      charstring c,
+      charstring d,
+      TypeWithUseUnion t
+    } with {
+      encode "XML";
+      variant "namespace as 'schema' prefix 'xsd'";
+      variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
+      variant "useType";
+      variant (b) "XSD:boolean";
+      variant (c) "XSD:token";
+      variant (d) "name as ''";
+      variant (d) "XSD:Name";
+    }
+
+    testcase tc_use_type_with_use_union() runs on C system C {
+
+      var UseTypeWithUseUnion my_type := { b := true }
+      var universal charstring expected := "<UseTypeWithUseUnion>true</UseTypeWithUseUnion>\n\n";
+
+      var octetstring result := enc_UseTypeWithUseUnion(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      var UseTypeWithUseUnion my_type_result := dec_UseTypeWithUseUnion(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+
+      my_type := { c := "aaa" }
+      expected := "<UseTypeWithUseUnion xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='c'>aaa</UseTypeWithUseUnion>\n\n";
+
+      result := enc_UseTypeWithUseUnion(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      my_type_result := dec_UseTypeWithUseUnion(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      my_type := { d := "name" }
+      expected := "<UseTypeWithUseUnion xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd0='http://www.w3.org/2001/XMLSchema' xsi:type='xsd0:Name'>name</UseTypeWithUseUnion>\n\n";
+      result := enc_UseTypeWithUseUnion(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      my_type_result := dec_UseTypeWithUseUnion(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      // Currently works incorrectly: Bug 507270
+      /*my_type := { t := { cs := "cs" } }
+      expected := "<UseTypeWithUseUnion xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd1='http://www.w3.org/2001/XMLSchema' xsi:type='xsd1:Name'>name</UseTypeWithUseUnion>\n\n";
+      result := enc_UseTypeWithUseUnion(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      my_type_result := dec_UseTypeWithUseUnion(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }*/
+
+      setverdict(pass);
+    }
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+    type union UseUnionWithoutXSDType {
+      boolean b,
+      charstring c,
+      charstring d
+    } with {
+      encode "XML";
+      variant "namespace as 'schema' prefix 'xsd'";
+      variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
+      variant "useUnion";
+    }
+
+    testcase tc_without_xsd_type() runs on C system C {
+
+      var UseUnionWithoutXSDType my_type := { b := true }
+      var universal charstring expected := "<UseUnionWithoutXSDType xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>true</UseUnionWithoutXSDType>\n\n";
+
+      var octetstring result := enc_UseUnionWithoutXSDType(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      var UseUnionWithoutXSDType my_type_result := dec_UseUnionWithoutXSDType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      my_type := { c := "c" }
+      expected := "<UseUnionWithoutXSDType xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>c</UseUnionWithoutXSDType>\n\n";
+
+      result := enc_UseUnionWithoutXSDType(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      my_type_result := dec_UseUnionWithoutXSDType(result);
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      my_type := { d := "d" }
+      expected := "<UseUnionWithoutXSDType xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>d</UseUnionWithoutXSDType>\n\n";
+
+      result := enc_UseUnionWithoutXSDType(my_type);
+      if (oct2unichar(result) != expected) {
+        setverdict(fail, match(oct2unichar(result), expected));
+      }
+      my_type_result := dec_UseUnionWithoutXSDType(result);
+      my_type := { c := "d" } // No xsi:type
+      if (my_type_result != my_type) {
+        setverdict(fail, match(my_type_result, my_type));
+      }
+
+      setverdict(pass);
+    }
+
+    control {
+        execute(tc_unnamed());
+        execute(tc_named());
+        execute(tc_use_type_with_use_union());
+        execute(tc_without_xsd_type());
+    }
+}
diff --git a/regression_test/XML/XSDBaseType/schema.ttcn b/regression_test/XML/XSDBaseType/schema.ttcn
new file mode 100644
index 0000000000000000000000000000000000000000..886dd427c2150875cfa8539326cab30826bc381f
--- /dev/null
+++ b/regression_test/XML/XSDBaseType/schema.ttcn
@@ -0,0 +1,186 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Szabo, Bence Janos
+ *
+ ******************************************************************************/
+module schema {
+
+
+import from XSD all;
+
+
+type union E21unnamed
+{
+	XSD.String alt_,
+	XSD.NormalizedString alt_1,
+	XSD.Token alt_2,
+	XSD.Name alt_3,
+	XSD.NMTOKEN alt_4,
+	XSD.NCName alt_5,
+	XSD.ID alt_6,
+	XSD.IDREF alt_7,
+	XSD.ENTITY alt_8,
+	XSD.HexBinary alt_9,
+	XSD.Base64Binary alt_10,
+	XSD.AnyURI alt_11,
+	XSD.Language alt_12,
+	XSD.Integer alt_13,
+	XSD.PositiveInteger alt_14,
+	XSD.NonPositiveInteger alt_15,
+	XSD.NegativeInteger alt_16,
+	XSD.NonNegativeInteger alt_17,
+	XSD.Long alt_18,
+	XSD.UnsignedLong alt_19,
+	XSD.Int alt_20,
+	XSD.UnsignedInt alt_21,
+	XSD.Short alt_22,
+	XSD.UnsignedShort alt_23,
+	XSD.Byte alt_24,
+	XSD.UnsignedByte alt_25,
+	XSD.Decimal alt_26,
+	XSD.Float alt_27,
+	XSD.Double alt_28,
+	XSD.Duration alt_29,
+	XSD.DateTime alt_30,
+	XSD.Time alt_31,
+	XSD.Date alt_32,
+	XSD.GYearMonth alt_33,
+	XSD.GYear alt_34,
+	XSD.GMonthDay alt_35,
+	XSD.GDay alt_36,
+	XSD.GMonth alt_37,
+	XSD.Boolean alt_38
+}
+with {
+  variant "name as uncapitalized";
+  variant "useUnion";
+  variant (alt_) "name as ''";
+  variant (alt_1) "name as ''";
+  variant (alt_2) "name as ''";
+  variant (alt_3) "name as ''";
+  variant (alt_4) "name as ''";
+  variant (alt_5) "name as ''";
+  variant (alt_6) "name as ''";
+  variant (alt_7) "name as ''";
+  variant (alt_8) "name as ''";
+  variant (alt_9) "name as ''";
+  variant (alt_10) "name as ''";
+  variant (alt_11) "name as ''";
+  variant (alt_12) "name as ''";
+  variant (alt_13) "name as ''";
+  variant (alt_14) "name as ''";
+  variant (alt_15) "name as ''";
+  variant (alt_16) "name as ''";
+  variant (alt_17) "name as ''";
+  variant (alt_18) "name as ''";
+  variant (alt_19) "name as ''";
+  variant (alt_20) "name as ''";
+  variant (alt_21) "name as ''";
+  variant (alt_22) "name as ''";
+  variant (alt_23) "name as ''";
+  variant (alt_24) "name as ''";
+  variant (alt_25) "name as ''";
+  variant (alt_26) "name as ''";
+  variant (alt_27) "name as ''";
+  variant (alt_28) "name as ''";
+  variant (alt_29) "name as ''";
+  variant (alt_30) "name as ''";
+  variant (alt_31) "name as ''";
+  variant (alt_32) "name as ''";
+  variant (alt_33) "name as ''";
+  variant (alt_34) "name as ''";
+  variant (alt_35) "name as ''";
+  variant (alt_36) "name as ''";
+  variant (alt_37) "name as ''";
+  variant (alt_38) "name as ''";
+  //variant (alt_38) "text 'true' as '1'";
+  //variant (alt_38) "text 'false' as '0'";
+};
+
+
+type E21unnamed UnnamedType
+with {
+  variant "element";
+};
+
+
+type union E21named
+{
+	XSD.String string,
+	XSD.NormalizedString normalizedString,
+	XSD.Token token,
+	XSD.Name name,
+	XSD.NMTOKEN nMTOKEN,
+	XSD.NCName nCName,
+	XSD.ID iD,
+	XSD.IDREF iDREF,
+	XSD.ENTITY eNTITY,
+	XSD.HexBinary hexBinary,
+	XSD.Base64Binary base64Binary,
+	XSD.AnyURI anyURI,
+	XSD.Language language_,
+	XSD.Integer integer_,
+	XSD.PositiveInteger positiveInteger,
+	XSD.NonPositiveInteger nonPositiveInteger,
+	XSD.NegativeInteger negativeInteger,
+	XSD.NonNegativeInteger nonNegativeInteger,
+	XSD.Long long,
+	XSD.UnsignedLong unsignedLong,
+	XSD.Int int,
+	XSD.UnsignedInt unsignedInt,
+	XSD.Short short,
+	XSD.UnsignedShort unsignedShort,
+	XSD.Byte byte,
+	XSD.UnsignedByte unsignedByte,
+	XSD.Decimal decimal,
+	XSD.Float float_,
+	XSD.Double double,
+	XSD.Duration duration,
+	XSD.DateTime dateTime,
+	XSD.Time time,
+	XSD.Date date,
+	XSD.GYearMonth gYearMonth,
+	XSD.GYear gYear,
+	XSD.GMonthDay gMonthDay,
+	XSD.GDay gDay,
+	XSD.GMonth gMonth,
+	XSD.Boolean boolean_
+}
+with {
+  variant "name as uncapitalized";
+  variant "useUnion";
+  variant (name) "name as capitalized";
+  variant (nMTOKEN) "name as capitalized";
+  variant (nCName) "name as capitalized";
+  variant (iD) "name as capitalized";
+  variant (iDREF) "name as capitalized";
+  variant (eNTITY) "name as capitalized";
+  variant (language_) "name as 'language'";
+  variant (integer_) "name as 'integer'";
+  variant (float_) "name as 'float'";
+  variant (boolean_) "name as 'boolean'";
+  //variant (boolean_) "text 'true' as '1'";
+  //variant (boolean_) "text 'false' as '0'";
+};
+
+
+type E21named NamedType
+with {
+  variant "element";
+  
+  variant "namespace as 'schema' prefix 'xsd0'"; // this will force the perfix of the XSD schema to be xsd1
+};
+
+
+}
+with {
+  encode "XML";
+  variant "namespace as 'schema' prefix 'xsd'";
+  variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
+}
diff --git a/regression_test/XML/xsdConverter/HQ48576/HQ48576Test.ttcn b/regression_test/XML/xsdConverter/HQ48576/HQ48576Test.ttcn
index 85f3eefd83d2dbfeb20d4b5a0329f593f5127539..3802fdb98c9bc5eff8d21377f69260396d828368 100644
--- a/regression_test/XML/xsdConverter/HQ48576/HQ48576Test.ttcn
+++ b/regression_test/XML/xsdConverter/HQ48576/HQ48576Test.ttcn
@@ -19,7 +19,10 @@ type component C {}
 external function enc_imsi(in ImsiType i) return octetstring
 with { extension "prototype(convert) encode(XER:XER_EXTENDED)" }
 
-const charstring  c_cali := "<imsiType xmlns='http://schemas.ericsson.com/pg/hlr/13.5/'>califragilistic</imsiType>\n\n";
+external function dec_imsi(in octetstring stream) return ImsiType
+with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }
+
+const charstring  c_cali := "<imsiType xmlns='http://schemas.ericsson.com/pg/hlr/13.5/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type='xsd:string'>califragilistic</imsiType>\n\n";
 const octetstring o_cali := char2oct(c_cali);
 
 const charstring  c_all  := "<imsiType xmlns='http://schemas.ericsson.com/pg/hlr/13.5/'>ALL</imsiType>\n\n";
@@ -29,17 +32,28 @@ const octetstring o_all  := char2oct(c_all);
 // The point of this test is to chec that xsd2ttcn does not crash.
 testcase tc1() runs on C
 {
+  var ImsiType v_result;
   var ImsiType v_imsi := { alt_ := "califragilistic" };
   var octetstring o := enc_imsi(v_imsi);
   action(o);
   if (match(o, o_cali)) { setverdict(pass); }
   else { setverdict(fail, match(o, o_cali)); }
+  v_result := dec_imsi(o);
+  if (match(v_result, v_imsi)) { setverdict(pass); }
+  else { setverdict(fail, match(v_result, v_imsi)); }
+
   
   v_imsi := { alt_1 := aLL }
   o := enc_imsi(v_imsi);
   action(o);
   if (match(o, o_all)) { setverdict(pass); }
   else { setverdict(fail, match(o, o_all)); }
+  v_result := dec_imsi(o);
+  // Will be encoded into the first field (alt_)
+  var charstring all_ := "ALL";
+  v_imsi := { alt_ := all_ }
+  if (match(v_result, v_imsi)) { setverdict(pass); }
+  else { setverdict(fail, match(v_result, v_imsi)); }
 }
 
 control {