=== modified file 'src/com/goldencode/p2j/persist/serial/XmlImport.java'
--- src/com/goldencode/p2j/persist/serial/XmlImport.java	2022-11-14 15:55:42 +0000
+++ src/com/goldencode/p2j/persist/serial/XmlImport.java	2022-11-17 06:39:53 +0000
@@ -43,6 +43,7 @@
 **     IAS 20220926 Fixed READ-XMLSCHEMA support.
 **     IAS 20221014 More fixes to READ-XMLSCHEMA support.
 **     IAS 20221018 Fixed processing of 'now' and 'today' INITIAL attribute value.
+**     IAS 20221116 Fixed READ-XMLSCHEMA support for DATASET..
 */
 
 /*
@@ -102,6 +103,7 @@
 
 import java.io.*;
 import java.lang.reflect.*;
+import java.nio.file.*;
 import java.util.*;
 import java.util.function.*;
 import java.util.logging.*;
@@ -177,12 +179,18 @@
    /** The future name of the read temp-table. */
    private String ttName = null;
    
+   /** The future namesapece prefix of the read temp-table. */
+   private String ttPrefix = null;
+
    /** The desired mapping of fields to new type, if one is defined. */
    private final Map<String, String> fieldTypeMapping;
    
    /** 'External' schema location, if one is provided. */
    private final String schemaLocation;
    
+   /** Flag indicating that we're reading external schema */
+   private boolean external = false;
+
    /**
     * The set of temp-table builders for a dataset. They are mapped by their (XML-) names. They
     * are collected while parsing the schema and since their indexes are available only at the end
@@ -1016,7 +1024,9 @@
    private boolean readDatasetSchema(boolean verify)
    throws XMLStreamException
    {
+      Map<String, TempTableBuilder> extenalSchemas = new HashMap<>();
       Relation keyrefRel = null;
+      String nsPrefix = null;
       while (reader.hasNext())
       {
          int type = reader.next();
@@ -1052,17 +1062,32 @@
                         if (ds._dynamic())
                         {
                            ds.name(datasetName);
+                           nsPrefix = getXmlAttribute("prodata:prefix");
+                           ds.namespacePrefix(nsPrefix);
                         }
                         // else simply ignore it (?)
                      }
                      else 
                      {
                         String tableName = getXmlAttribute("prodata:tableName");
+                        TempTableBuilder ttb = null;
+                        String tableRef = null;
                         if (tableName == null)
                         {
                            // if dedicated attribute not found, use the xml name attribute
                            tableName = getXmlAttribute("name");
                         }
+                        if (tableName == null)
+                        {
+                          tableRef = getXmlAttribute("ref");
+                          ttb = extenalSchemas.get(tableRef);
+                          if (ttb == null)
+                          {
+                             throw new IllegalStateException("Unknown table reference: [" 
+                                                              + tableRef + "]");
+                          }
+                          tableName = removeNsPrefix(tableRef);
+                        }
                         handle buffer = ds.bufferHandle(tableName);
                         if (verifySchemaMode == Verify.STRICT && verify && !buffer._isValid())
                         {
@@ -1074,15 +1099,64 @@
                            // Temp-table '<table>' not found in XML Schema
                            return false;
                         }
-                        if (!readTableSchema(tableName, null))
+                        if (ttb != null)
+                        {
+                           tables.put(tableName, ttb);
+                           String xmlNodeName = ttb.getXmlNodeName().getValue();
+                           tablesByXmlName.put(
+                                 new CaseInsensitiveString(xmlNodeName == null ? tableName : 
+                                                                                 xmlNodeName), 
+                                 tableName);
+                           
+                        }
+                        else 
+                        {
+                           if (!readTableSchema(tableName, null))
+                           {
+                              return false;
+                           }
+                        }
+                     }
+                     break;
+                     
+                  case "import":
+                     if (ds != null)
+                     {
+                        String schemaLocation = getXmlAttribute("schemaLocation");
+                        String extPath = !Serializator.TYPE_FILE.equals(
+                                 source.getType().toUpperCase()) ? null : 
+                                 Paths.get(source.getFileName()).getParent().toString() + 
+                                                                  "/" + schemaLocation;
+                        if (extPath == null)
+                        {
+                           ErrorManager.recordOrThrowError(
+                              new int[] {293, 13101, 13032}, 
+                              new String[] {
+                                 "** \"" + schemaLocation + "\" was not found",
+                                 "Unable to load imported or included schema: " + schemaLocation,
+                                 "Unable to create Temp-Table or dataset schema from XML Schema"
+                              }, 
+                              false, false, true);
+                        }
+                        String ns = getXmlAttribute("namespace");
+                        XmlImport ext = new XmlImport(new SourceData("file", extPath), 
+                                 null, schemaLocation, false, null, null);
+                        ext.external = true;
+                        TempTableBuilder ttb = new TempTableBuilder();
+                        if (!ext.importTempTableSchema(ttb)) 
                         {
                            return false;
                         }
+                        String tableName = ext.ttName;
+                        String tableRef = (ext.ttPrefix == null ? "" : 
+                                                            ext.ttPrefix + ":") + tableName;
+                        extenalSchemas.put(tableRef, ttb);
                      }
                      break;
                      
                   case ELEM_SCHEMA:
                      // check "xmlns:xsd", "xmlns", and "xmlns:prodata" attributes
+                     ds.namespaceURI(getXmlAttribute("targetNamespace"));
                      break;
                      
                   case "unique":
@@ -1090,7 +1164,7 @@
                      indexName = getXmlAttribute("prodata:indexName");
                      primary = Boolean.parseBoolean(getXmlAttribute("prodata:primaryIndex"));
                      word = Boolean.parseBoolean(getXmlAttribute("prodata:wordIndex"));
-                     if (!readIndex(getXmlAttribute("name"), indexName, null, primary, true, word))
+                     if (!readIndex(getXmlAttribute("name"), indexName, nsPrefix, primary, true, word))
                      {
                         return false;
                      }
@@ -1101,7 +1175,7 @@
                      indexName = getXmlAttribute("prodata:indexName");
                      primary = Boolean.parseBoolean(getXmlAttribute("prodata:primaryIndex"));
                      word = Boolean.parseBoolean(getXmlAttribute("prodata:wordIndex"));
-                     if (!readIndex(getXmlAttribute("name"), indexName, null, primary, false, word))
+                     if (!readIndex(getXmlAttribute("name"), indexName, nsPrefix, primary, false, word))
                      {
                         return false;
                      }
@@ -1116,7 +1190,7 @@
                      
                      // found a relation based on a unique index
                      indexName = getXmlAttribute("refer");
-                     P2JIndex uidx = uniqueIndexes.get(indexName);
+                     P2JIndex uidx = uniqueIndexes.get(removeNsPrefix(indexName));
                      if (uidx == null)
                      {
                         throw new XMLStreamException(
@@ -1141,7 +1215,7 @@
                   case "selector":
                      if (keyrefRel != null)
                      {
-                        keyrefRel.setChild(getXmlAttribute("xpath"));
+                        keyrefRel.setChild(nsPrefix, getXmlAttribute("xpath"));
                      }
                      
                      // otherwise, it is not related to unique index based relation
@@ -1150,7 +1224,7 @@
                   case "field":
                      if (keyrefRel != null)
                      {
-                        keyrefRel.addChildField(getXmlAttribute("xpath"));
+                        keyrefRel.addChildField(nsPrefix, getXmlAttribute("xpath"));
                      }
                      
                      // otherwise, it is not related to unique index based relation
@@ -1171,6 +1245,7 @@
                switch(name)
                {
                   case ELEM_SCHEMA:
+                     processDsBuffers();
                      int numTables = ds.numBuffers().intValue();
                      if (verifySchemaMode == Verify.STRICT)
                      {
@@ -1343,6 +1418,40 @@
       
       throw new XMLStreamException("Unexpected EOS in readDatasetSchema().", reader.getLocation());
    }
+
+   /**
+    * Remove the namespace prefix from the qualified name
+    * 
+    * @param  qname
+    *         qualified name to be simplified
+    *         
+    * @return name w/o prefix
+    */
+   private String removeNsPrefix(String qname)
+   {
+      int pos = qname.indexOf(':');
+      return pos > 0 ? qname.substring(pos+1) : qname;
+      
+   }
+   /**
+    * Process buffers for the found dataset tables.
+    */
+   private void processDsBuffers()
+   {
+      BufferImpl[] dsBuffers = new BufferImpl[tables.size()];
+      int nb = 0; 
+      for (Map.Entry<String, AbstractTempTable> e: tables.entrySet())
+      {
+         TempTableBuilder ttb = (TempTableBuilder)e.getValue();
+         ttb.tempTablePrepare(e.getKey());
+         Buffer tbuffer = ttb.defaultBufferHandle().unwrapBuffer();
+         if (tbuffer != null)
+         {
+            dsBuffers[nb++] = (BufferImpl)tbuffer;
+         }
+      }
+      ds.setBuffers(dsBuffers);
+   }
    
    /**
     * Reads and processes an {@code AbstractTempTable} schema. If the {@code TempTable} is in CLEAR state, the
@@ -1379,7 +1488,6 @@
                }
                
                name = reader.getLocalName();
-               
                // index properties:
                String indexName = null;
                boolean primary = false;
@@ -1389,7 +1497,7 @@
                {
                   case "element":
                      boolean isTT = Boolean.parseBoolean(getXmlAttribute("prodata:proTempTable"));
-                     if (isTT) 
+                     if (isTT || external) 
                      {
                         String tableName = getXmlAttribute("prodata:tableName");
                         if (tableName == null)
@@ -1408,6 +1516,7 @@
                         undo = Boolean.parseBoolean(getXmlAttribute("prodata:undo"));
                         
                         ttName = tableName;
+                        ttPrefix = nsPrefix;
                         if (!readTableSchema(tableName, nsPrefix))
                         {
                            return false;
@@ -1479,7 +1588,7 @@
                      {
                         ttb.namespaceURI(nsUri);
                      }
-                     if (!ttb.tempTablePrepare(ttName).booleanValue())
+                     if (!external && !ttb.tempTablePrepare(ttName).booleanValue())
                      {
                         // TODO: report error? already reported? 
                         return false;
@@ -1561,11 +1670,7 @@
                         xpath = xpath.substring(3);
                      }
                      
-                     if (nsPrefix != null && xpath.startsWith(nsPrefix))
-                     {
-                        // drop the [nsPrefix], including the COLON, if any
-                        xpath = xpath.substring(nsPrefix.length() + 1);
-                     }
+                     xpath = removeNsPrefix(xpath);
                      
                      if (tablesByXmlName != null)
                      {
@@ -1600,12 +1705,7 @@
                      break;
                      
                   case "field":
-                     String field = getXmlAttribute(unique ? "xpath" : "name");
-                     if (nsPrefix != null && field.startsWith(nsPrefix))
-                     {
-                        // drop the [nsPrefix], including the COLON, if any
-                        field = field.substring(nsPrefix.length() + 1);
-                     }
+                     String field = removeNsPrefix(getXmlAttribute(unique ? "xpath" : "name"));
                      boolean desc = Boolean.parseBoolean(getXmlAttribute("prodata:descending"));
                      if (ttb != null && !ttb._prepared())
                      {
@@ -2934,23 +3034,39 @@
       /**
        * Sets the name of the child buffer. If needed the {@code "..//"} prefix is dropped.
        * 
+       * @param   nsPrefix
+       *          namespace prefix.
+       *          
        * @param   xpath
        *          The name of the child buffer, as read from XML.
        */
-      public void setChild(String xpath)
+      public void setChild(String nsPrefix, String xpath)
       {
-         child = xpath.startsWith(".//") ? xpath.substring(3) : xpath; 
+         if (xpath.startsWith(".//"))
+         {
+            xpath = xpath.substring(3);
+         }
+         if (nsPrefix != null && xpath.startsWith(nsPrefix))
+         {
+            xpath = xpath.substring(nsPrefix.length() + 1);
+         }
+
+         child = xpath; 
       }
       
       /**
        * Adds a new field to be used on child side of the relation.
-       * 
+       * @param   nsPrefix 
+       *          namespace prefix
+       *          
        * @param   field
        *          The name of the field.
        */
-      public void addChildField(String field)
+      public void addChildField(String nsPrefix, String field)
       {
-         childFields.add(field);
+         childFields.add(nsPrefix != null && field.startsWith(nsPrefix) ?
+                  field.substring(nsPrefix.length() + 1) :
+                  field);
       }
       
       /**

