src/XSD2PHP/src/com/mikebevz/xsd2php/Wsdl.php
private function addImportToSchema($namespace, $code)
    {
        if (array_key_exists($namespace, $this->namespaces)) {
            if (in_array($namespace, $this->importedNamespaces)) {
                return;
            }

            $dom = $this->wsdl->toDomDocument();
            $dom->createAttributeNs($namespace, $code.":definitions");
            $importEl = $dom->createElement($this->xmlSchemaPreffix.":import");
            $nsAttr   = $dom->createAttribute("namespace");
            $txtNode  = $dom->createTextNode($namespace);
            $nsAttr->appendChild($txtNode);

            $nsAttr2   = $dom->createAttribute("schemaLocation");
            $schemaLocation = $this->getSchemaLocation($namespace);
            $publicSchema = $this->copyToPublic($schemaLocation, true);
            $publicSchema = $this->copyToPublic($schemaLocation, true);
            $schemaUrl = $this->importsToAbsUrl($publicSchema, $this->getSchemasPath());

            $txtNode2  = $dom->createTextNode($schemaUrl);
            $nsAttr2->appendChild($txtNode2);

            $importEl->appendChild($nsAttr);
            $importEl->appendChild($nsAttr2);
            $this->wsdl->getSchema();
            $xpath = new \DOMXPath($dom);
            $query = "//*[local-name()='types']/child::*/*";
            $firstElement = $xpath->query($query);

            if (!is_object($firstElement->item(0))) {
                $query = "//*[local-name()='types']/child::*";
                $schema = $xpath->query($query);
                $schema->item(0)->appendChild($importEl);
            } else {
                $this->wsdl->getSchema()->insertBefore($importEl, $firstElement->item(0));
            }

            array_push($this->importedNamespaces, $namespace);
        }
    }
private function addImportToSchema($namespace, $code)
    {
        if (array_key_exists($namespace, $this->namespaces)) {
            if (in_array($namespace, $this->importedNamespaces)) {
                return;
            }

            $dom = $this->wsdl->toDomDocument();
            $dom->createAttributeNs($namespace, $code.":definitions");
            $importEl = $dom->createElement($this->xmlSchemaPreffix.":import");
            $nsAttr   = $dom->createAttribute("namespace");
            $txtNode  = $dom->createTextNode($namespace);
            $nsAttr->appendChild($txtNode);

            $nsAttr2   = $dom->createAttribute("schemaLocation");
            $schemaLocation = $this->getSchemaLocation($namespace);
            $publicSchema = $this->copyToPublic($schemaLocation, true);
            $publicSchema = $this->copyToPublic($schemaLocation, true);
            $schemaUrl = $this->importsToAbsUrl($publicSchema, $this->getSchemasPath());

            $txtNode2  = $dom->createTextNode($schemaUrl);
            $nsAttr2->appendChild($txtNode2);

            $importEl->appendChild($nsAttr);
            $importEl->appendChild($nsAttr2);
            $this->wsdl->getSchema();
            $xpath = new \DOMXPath($dom);
            $query = "//*[local-name()='types']/child::*/*";
            $firstElement = $xpath->query($query);

            if (!is_object($firstElement->item(0))) {
                $query = "//*[local-name()='types']/child::*";
                $schema = $xpath->query($query);
                $schema->item(0)->appendChild($importEl);
            } else {
                $this->wsdl->getSchema()->insertBefore($importEl, $firstElement->item(0));
            }

            array_push($this->importedNamespaces, $namespace);
        }
    }
Add xsd:import tag to XML schema before any childs added

@param string $namespace Namespace URI
@param string $code      Shortcut for namespace, fx, ns0. Returned by getNsCode()

@return void