diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/ietf_params_xml_ns_rlmi_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/ietf_params_xml_ns_rlmi_e.ttcn
index 58b18a11689383e53d32f23fde57a1c0651bce69..599eb1d79e746e85931114f5cc80cab85e998c73 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/ietf_params_xml_ns_rlmi_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/ietf_params_xml_ns_rlmi_e.ttcn
@@ -56,7 +56,7 @@ type record List
 	XSD.AnyURI uri,
 	XSD.UnsignedInt version,
 	record of XSD.String attr optional,
-	record of XSD.Name name_list,
+	record of Name name_list,
 	record of Resource resource_list
 }
 with {
@@ -80,7 +80,7 @@ type record Resource
 {
 	XSD.AnyURI uri,
 	record of XSD.String attr optional,
-	record of XSD.Name name_list,
+	record of Name name_list,
 	record of Instance instance_list
 }
 with {
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
index ff8d0f71a2b1faf69178db45e3a34a82925fb8a5..3609edd54b14cc176da4dd22d4c5d3a2517f758d 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
@@ -54,7 +54,7 @@ import from XSD all;
     3 Built-in Datatypes */
 
 
-type XSD.Name NameA
+type Name NameA
 with {
   variant "element";
 };
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
index 8f1778ad2c2e5de16bfcdc1e78bd416cbf894c3a..52f4167960c5d6a8a2c02bdb3c866301846d3663 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
@@ -94,7 +94,7 @@ type XSD.AnyURI ID;
 
 type record TypeWithIDs
 {
-	XSD.ID id1,
+	ID id1,
 	XSD.ID id2
 };
 
diff --git a/xsdconvert/AttributeType.cc b/xsdconvert/AttributeType.cc
index ad75c73f4e0297a8c383179a35e0c87c7591ec1d..1022a1a03c8969eb5804e88d480ee78a7e2aebbc 100644
--- a/xsdconvert/AttributeType.cc
+++ b/xsdconvert/AttributeType.cc
@@ -97,7 +97,7 @@ void AttributeType::nameConversion_names(QualifiedNames& used_ns) {
   }else {
     q = QualifiedName(empty_string, empty_string);
   }
-  XSDName2TTCN3Name(name.convertedValue, used_names, field_name, res, var);
+  XSDName2TTCN3Name(name.convertedValue, empty_string, used_names, field_name, res, var);
   name.convertedValue = res;
   addVariant(V_onlyValue, var);
   if (q.name != used_names.back().name) {
@@ -106,7 +106,7 @@ void AttributeType::nameConversion_names(QualifiedNames& used_ns) {
   }
 
   for (List<RootType*>::iterator st = nameDepList.begin(); st; st = st->Next) {
-    st->Data->setTypeValue(res);
+    st->Data->setTypeValueWoPrefix(res);
   }
 }
 
diff --git a/xsdconvert/ComplexType.cc b/xsdconvert/ComplexType.cc
index 88ebb407a64b76098e67b9522c01bb06720d78a3..ba4ba86fd8554c7ce2e36538e07119b022db559f 100644
--- a/xsdconvert/ComplexType.cc
+++ b/xsdconvert/ComplexType.cc
@@ -235,6 +235,9 @@ void ComplexType::loadWithValues() {
   
   const XMLParser::TagAttributes & atts = parser->getActualTagAttributes();
   
+  Mstring xsdPrefix = module->getxmlSchemaPrefixes().size() != 0 ?
+    (module->getxmlSchemaPrefixes().front() + ':') : empty_string;
+  
   switch (parser->getActualTagName()) {
     case n_sequence:
       if (!top && xsdtype != n_sequence && xsdtype != n_complexType && xsdtype != n_extension && xsdtype != n_restriction && xsdtype != n_element) {
@@ -468,7 +471,7 @@ void ComplexType::loadWithValues() {
     {
       ComplexType * any = new ComplexType(this);
       any->name.upload(Mstring("elem"));
-      any->type.upload(Mstring("string"), false);
+      any->type.upload(xsdPrefix + Mstring("string"), false);
       any->applyNamespaceAttribute(V_anyElement, atts.namespace_);
       any->setMinMaxOccurs(atts.minOccurs, atts.maxOccurs);
       any->setXsdtype(n_any);
@@ -480,7 +483,7 @@ void ComplexType::loadWithValues() {
       AttributeType * anyattr = new AttributeType(this);
       anyattr->setXsdtype(n_anyAttribute);
       anyattr->setNameOfField(Mstring("attr"));
-      anyattr->setTypeValue(Mstring("string"));
+      anyattr->setTypeValue(xsdPrefix + Mstring("string"));
       anyattr->setToAnyAttribute();
       anyattr->applyMinMaxOccursAttribute(0, ULLONG_MAX);
       anyattr->addNameSpaceAttribute(atts.namespace_);
@@ -597,7 +600,7 @@ void ComplexType::loadWithValues() {
       if (atts.mixed) {
         ComplexType * mixed = new ComplexType(this);
         mixed->name.upload(Mstring("embed_values"));
-        mixed->type.upload(Mstring("string"), false);
+        mixed->type.upload(xsdPrefix + Mstring("string"), false);
         mixed->setMinMaxOccurs(0, ULLONG_MAX, false);
         mixed->embed = true;
         complexfields.push_back(mixed);
@@ -844,7 +847,7 @@ void ComplexType::nameConversion(NameConversionMode conversion_mode, const List<
 
 void ComplexType::nameConversion_names(const List<NamespaceType> &) {
   Mstring res, var(module->getTargetNamespace());
-  XSDName2TTCN3Name(name.convertedValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
+  XSDName2TTCN3Name(name.convertedValue, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
   name.convertedValue = res;
   bool found = false;
   for (List<Mstring>::iterator vari = variant.begin(); vari; vari = vari->Next) {
@@ -858,7 +861,7 @@ void ComplexType::nameConversion_names(const List<NamespaceType> &) {
     addVariant(V_onlyValue, var);
   }
   for (List<RootType*>::iterator dep = nameDepList.begin(); dep; dep = dep->Next) {
-    dep->Data->setTypeValue(res);
+    dep->Data->setTypeValueWoPrefix(res);
   }
 }
 
@@ -909,7 +912,7 @@ void ComplexType::nameConversion_types(const List<NamespaceType> & ns) {
     setTypeValue(origTN->Data.name);
   } else {
     Mstring res, var;
-    XSDName2TTCN3Name(typeValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var, type.no_replace);
+    XSDName2TTCN3Name(typeValue, uri, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var, type.no_replace);
     setTypeValue(res);
   }
 }
@@ -936,14 +939,21 @@ void ComplexType::nameConversion_fields(const List<NamespaceType> & ns) {
 
     Mstring res, var;
     var = getModule()->getTargetNamespace();
-    XSDName2TTCN3Name(typeValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
+    List<NamespaceType>::iterator declNS;
+    for (declNS = module->getDeclaredNamespaces().begin(); declNS; declNS = declNS->Next) {
+      if (prefix == declNS->Data.prefix) {
+        break;
+      }
+    }
+    XSDName2TTCN3Name(typeValue, declNS ? declNS->Data.uri : empty_string,
+      TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
 
     field->Data->addVariant(V_onlyValue, var);
     var = getModule()->getTargetNamespace();
 
     if (field->Data->getName().list_extension) {
       field->Data->useNameListProperty();
-      XSDName2TTCN3Name(field->Data->getName().convertedValue,
+      XSDName2TTCN3Name(field->Data->getName().convertedValue, empty_string,
         used_field_names, field_name, res, var);
       field->Data->setNameValue(res);
       bool found_in_variant = false;
@@ -966,7 +976,7 @@ void ComplexType::nameConversion_fields(const List<NamespaceType> & ns) {
         field->Data->addVariant(V_untagged, empty_string, true);
       }
     } else {
-      XSDName2TTCN3Name(field->Data->getName().convertedValue,
+      XSDName2TTCN3Name(field->Data->getName().convertedValue, empty_string,
         used_field_names, field_name, res, var);
       field->Data->setNameValue(res);
       field->Data->addVariant(V_onlyValue, var);
@@ -2392,7 +2402,7 @@ void ComplexType::addTypeSubstitution(SimpleType * st){
   }
   element->top = false;
   complexfields.push_back(element);
-  element->setTypeValue(st->getName().convertedValue.getValueWithoutPrefix(':'));
+  element->setTypeValue(st->getName().convertedValue);
   element->setNameValue(st->getName().convertedValue.getValueWithoutPrefix(':'));
 }
 
diff --git a/xsdconvert/Constant.cc b/xsdconvert/Constant.cc
index f6f84eee9387bda148a084cc4e7b8ea521aeaa06..a33148eb382956cba71b584ccf2e5c465682b303 100644
--- a/xsdconvert/Constant.cc
+++ b/xsdconvert/Constant.cc
@@ -69,7 +69,7 @@ void Constant::nameConversion_types(const List<NamespaceType> & ns) {
     // otherwise the new value is always the same as the old.
   } else {
     Mstring res, var;
-    XSDName2TTCN3Name(value_str, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
+    XSDName2TTCN3Name(value_str, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
     setTypeValue(res);
   }
 }
diff --git a/xsdconvert/GeneralFunctions.cc b/xsdconvert/GeneralFunctions.cc
index e1f372bf94e1665315df45e1574afc682292b05e..b0f9778f497fd068444e4ce0d4e18498e7477a07 100644
--- a/xsdconvert/GeneralFunctions.cc
+++ b/xsdconvert/GeneralFunctions.cc
@@ -49,7 +49,8 @@ extern bool t_flag_used;
 // 				variant - generated variant string for TTCN-3
 //
 
-void XSDName2TTCN3Name(const Mstring& in_str, QualifiedNames & used_names, modeType type_of_the_name,
+void XSDName2TTCN3Name(const Mstring& in_str, const Mstring& in_namespace,
+  QualifiedNames & used_names, modeType type_of_the_name,
   Mstring & res, Mstring & variant, bool no_replace) {
   static const char* TTCN3_reserved_words[] = {
     "action", "activate", "address", "alive", "all", "alt", "altstep", "and", "and4b", "any", "any2unistr", "anytype", "apply",
@@ -150,7 +151,7 @@ void XSDName2TTCN3Name(const Mstring& in_str, QualifiedNames & used_names, modeT
     // if (type_of_the_name == type_reference_name || type_of_the_name == field_reference_name) {
 
     if (type_of_the_name == type_reference_name) {
-      if (isBuiltInType(res)) {
+      if (isBuiltInType(res) && (in_namespace == empty_string || in_namespace == XMLSchema)) {
         res[0] = (char)toupper(res[0]);
         res = "XSD." + res;
         return;
diff --git a/xsdconvert/GeneralFunctions.hh b/xsdconvert/GeneralFunctions.hh
index 3956b2434ebc1fac83d65ca202949f971214b75d..3648365d461d64e666af09832c2cc5731457abd8 100644
--- a/xsdconvert/GeneralFunctions.hh
+++ b/xsdconvert/GeneralFunctions.hh
@@ -25,7 +25,8 @@ enum modeType {
     type_reference_name, type_name, field_name, enum_id_name
 };
 
-void XSDName2TTCN3Name(const Mstring& in, QualifiedNames & used_names, modeType type_of_the_name,
+void XSDName2TTCN3Name(const Mstring& in, const Mstring& in_namespace,
+        QualifiedNames & used_names, modeType type_of_the_name,
         Mstring & res, Mstring & variant, bool no_replace = false);
 
 class ReferenceData;
diff --git a/xsdconvert/RootType.cc b/xsdconvert/RootType.cc
index 3b4b1c96eda5a8f8307bea807fdaee9594d7bc35..2bf3dd69b321f4eccf18869033c35a93c47df614 100644
--- a/xsdconvert/RootType.cc
+++ b/xsdconvert/RootType.cc
@@ -33,6 +33,8 @@ RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const Construct
 , maxOccurs(1)
 , min_mod(false)
 , max_mod(false){
+  Mstring xsdPrefix = module->getxmlSchemaPrefixes().size() != 0 ?
+    (module->getxmlSchemaPrefixes().front() + ':') : empty_string;
   switch (a_construct) {
     case c_schema:
     case c_annotation:
@@ -43,16 +45,16 @@ RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const Construct
     case c_unknown: // because when using fields in complextypes we set construct to c_unknown
     case c_simpleType:
       origin = from_simpleType;
-      type.upload(Mstring("anySimpleType"), false);
+      type.upload(xsdPrefix + Mstring("anySimpleType"), false);
       break;
     case c_element:
       origin = from_element;
-      type.upload(Mstring("anyType"), false);
+      type.upload(xsdPrefix + Mstring("anyType"), false);
       addVariant(V_element);
       break;
     case c_attribute:
       origin = from_attribute;
-      type.upload(Mstring("anySimpleType"), false);
+      type.upload(xsdPrefix + Mstring("anySimpleType"), false);
       addVariant(V_attribute);
       break;
     case c_complexType:
diff --git a/xsdconvert/RootType.hh b/xsdconvert/RootType.hh
index c93efd844711b46f044583d77e7ab07b6149fcf4..a3767c382f8947a93dee24673c03136376f4fac8 100644
--- a/xsdconvert/RootType.hh
+++ b/xsdconvert/RootType.hh
@@ -193,6 +193,11 @@ public:
   void setTypeValue(const Mstring& str) {
     type.convertedValue = str;
   }
+  
+  void setTypeValueWoPrefix(const Mstring& str) {
+    Mstring prefix = type.convertedValue.getPrefix(':');
+    type.convertedValue = prefix + ':' + str;
+  }
 
   void useNameListProperty() {
     name.convertedValue += "_list";
diff --git a/xsdconvert/SimpleType.cc b/xsdconvert/SimpleType.cc
index e8e7e42b25779894969bab486b7a8aadf08fed8f..e853f942725ff1c66e412b40d4cf06c636223d33 100644
--- a/xsdconvert/SimpleType.cc
+++ b/xsdconvert/SimpleType.cc
@@ -525,7 +525,8 @@ void SimpleType::setReference(const Mstring& ref, bool only_name_dependency) {
     if (name.convertedValue.empty()) {
       name.upload(ref);
     }
-    if (type.convertedValue.empty() || type.convertedValue == "anySimpleType") {
+    if (type.convertedValue.empty() ||
+        type.convertedValue.getValueWithoutPrefix(':') == "anySimpleType") {
       type.upload(ref);
     }
     bool found = false;
@@ -769,11 +770,11 @@ void SimpleType::nameConversion(NameConversionMode conversion_mode, const List<N
 
 void SimpleType::nameConversion_names() {
   Mstring res, var(module->getTargetNamespace());
-  XSDName2TTCN3Name(name.convertedValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
+  XSDName2TTCN3Name(name.convertedValue, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
   name.convertedValue = res;
   addVariant(V_onlyValue, var);
   for (List<RootType*>::iterator st = nameDepList.begin(); st; st = st->Next) {
-    st->Data->setTypeValue(res);
+    st->Data->setTypeValueWoPrefix(res);
   }
   if (outside_reference.get_ref() != NULL && defaultForEmptyConstant!= NULL) {
     // We don't know if the name conversion already happened on the get_ref()
@@ -817,7 +818,7 @@ void SimpleType::nameConversion_types(const List<NamespaceType> & ns) {
     // otherwise the new value is always the same as the old.
   } else {
     Mstring res, var;
-    XSDName2TTCN3Name(value_str, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
+    XSDName2TTCN3Name(value_str, uri, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
     setTypeValue(res);
   }
 }
@@ -1274,7 +1275,7 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
       const LengthType & length = parent->getLength();
       if (length.lower <= facet->Data.size() && facet->Data.size() <= length.upper) {
         Mstring res, var;
-        XSDName2TTCN3Name(facet->Data, items_string, enum_id_name, res, var);
+        XSDName2TTCN3Name(facet->Data, empty_string, items_string, enum_id_name, res, var);
         text_variants.push_back(var);
         converted_facets.push_back(res);
       }
@@ -1341,7 +1342,7 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
     List<Mstring> text_variants;
     for (List<Mstring>::iterator facet = facets.begin(); facet; facet = facet->Next) {
       Mstring res, var;
-      XSDName2TTCN3Name(facet->Data, items_time, enum_id_name, res, var);
+      XSDName2TTCN3Name(facet->Data, empty_string, items_time, enum_id_name, res, var);
       text_variants.push_back(var);
       converted_facets.push_back(res);
     }