You are here

function XMLSchema::serializeSchema in Salesforce Suite 5

Same name in this branch
  1. 5 includes/nusoap.php \XMLSchema::serializeSchema()
  2. 5 includes/nusoap.orig.php \XMLSchema::serializeSchema()
Same name and namespace in other branches
  1. 5.2 includes/nusoap.php \XMLSchema::serializeSchema()
  2. 5.2 includes/nusoap.orig.php \XMLSchema::serializeSchema()

* serialize the schema * * @access public

File

includes/nusoap.php, line 1491

Class

XMLSchema
parses an XML Schema, allows access to it's data, other utility methods no validation... yet. very experimental and limited. As is discussed on XML-DEV, I'm one of the people that just doesn't have time to read the spec(s) thoroughly,…

Code

function serializeSchema() {
  $schemaPrefix = $this
    ->getPrefixFromNamespace($this->XMLSchemaVersion);
  $xml = '';

  // imports
  if (sizeof($this->imports) > 0) {
    foreach ($this->imports as $ns => $list) {
      foreach ($list as $ii) {
        if ($ii['location'] != '') {
          $xml .= " <{$schemaPrefix}:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
        }
        else {
          $xml .= " <{$schemaPrefix}:import namespace=\"" . $ns . "\" />\n";
        }
      }
    }
  }

  // complex types
  foreach ($this->complexTypes as $typeName => $attrs) {
    $contentStr = '';

    // serialize child elements
    if (isset($attrs['elements']) && count($attrs['elements']) > 0) {
      foreach ($attrs['elements'] as $element => $eParts) {
        if (isset($eParts['ref'])) {
          $contentStr .= "   <{$schemaPrefix}:element ref=\"{$element}\"/>\n";
        }
        else {
          $contentStr .= "   <{$schemaPrefix}:element name=\"{$element}\" type=\"" . $this
            ->contractQName($eParts['type']) . "\"";
          foreach ($eParts as $aName => $aValue) {

            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
            if ($aName != 'name' && $aName != 'type') {
              $contentStr .= " {$aName}=\"{$aValue}\"";
            }
          }
          $contentStr .= "/>\n";
        }
      }

      // compositor wraps elements
      if (isset($attrs['compositor']) && $attrs['compositor'] != '') {
        $contentStr = "  <{$schemaPrefix}:{$attrs['compositor']}>\n" . $contentStr . "  </{$schemaPrefix}:{$attrs['compositor']}>\n";
      }
    }

    // attributes
    if (isset($attrs['attrs']) && count($attrs['attrs']) >= 1) {
      foreach ($attrs['attrs'] as $attr => $aParts) {
        $contentStr .= "    <{$schemaPrefix}:attribute";
        foreach ($aParts as $a => $v) {
          if ($a == 'ref' || $a == 'type') {
            $contentStr .= " {$a}=\"" . $this
              ->contractQName($v) . '"';
          }
          elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
            $contentStr .= ' wsdl:arrayType="' . $this
              ->contractQName($v) . '"';
          }
          else {
            $contentStr .= " {$a}=\"{$v}\"";
          }
        }
        $contentStr .= "/>\n";
      }
    }

    // if restriction
    if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
      $contentStr = "   <{$schemaPrefix}:restriction base=\"" . $this
        ->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </{$schemaPrefix}:restriction>\n";

      // complex or simple content
      if (isset($attrs['elements']) && count($attrs['elements']) > 0 || isset($attrs['attrs']) && count($attrs['attrs']) > 0) {
        $contentStr = "  <{$schemaPrefix}:complexContent>\n" . $contentStr . "  </{$schemaPrefix}:complexContent>\n";
      }
    }

    // finalize complex type
    if ($contentStr != '') {
      $contentStr = " <{$schemaPrefix}:complexType name=\"{$typeName}\">\n" . $contentStr . " </{$schemaPrefix}:complexType>\n";
    }
    else {
      $contentStr = " <{$schemaPrefix}:complexType name=\"{$typeName}\"/>\n";
    }
    $xml .= $contentStr;
  }

  // simple types
  if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
    foreach ($this->simpleTypes as $typeName => $eParts) {
      $xml .= " <{$schemaPrefix}:simpleType name=\"{$typeName}\">\n  <{$schemaPrefix}:restriction base=\"" . $this
        ->contractQName($eParts['type']) . "\"/>\n";
      if (isset($eParts['enumeration'])) {
        foreach ($eParts['enumeration'] as $e) {
          $xml .= "  <{$schemaPrefix}:enumeration value=\"{$e}\"/>\n";
        }
      }
      $xml .= " </{$schemaPrefix}:simpleType>";
    }
  }

  // elements
  if (isset($this->elements) && count($this->elements) > 0) {
    foreach ($this->elements as $element => $eParts) {
      $xml .= " <{$schemaPrefix}:element name=\"{$element}\" type=\"" . $this
        ->contractQName($eParts['type']) . "\"/>\n";
    }
  }

  // attributes
  if (isset($this->attributes) && count($this->attributes) > 0) {
    foreach ($this->attributes as $attr => $aParts) {
      $xml .= " <{$schemaPrefix}:attribute name=\"{$attr}\" type=\"" . $this
        ->contractQName($aParts['type']) . "\"\n/>";
    }
  }

  // finish 'er up
  $el = "<{$schemaPrefix}:schema targetNamespace=\"{$this->schemaTargetNamespace}\"\n";
  foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
    $el .= " xmlns:{$nsp}=\"{$ns}\"\n";
  }
  $xml = $el . ">\n" . $xml . "</{$schemaPrefix}:schema>\n";
  return $xml;
}