|
@@ -72,6 +72,30 @@ class XML {
|
|
|
$xmlWriter->endDocument();
|
|
$xmlWriter->endDocument();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static function findTargetNamespace($docArray) {
|
|
|
|
|
+ return V::get('targetNamespace', '', $docArray[1]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function findSimpleTypeNode($docArray, $name) {
|
|
|
|
|
+ foreach ($docArray[2] as $child) {
|
|
|
|
|
+ if ('simpleType' === self::getTagName($child[0])) {
|
|
|
|
|
+ if ($name === $child[1]['name']) {
|
|
|
|
|
+ return $child;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function findTargetNamespacePrefix($docArray) {
|
|
|
|
|
+ $tns = self::findTargetNamespace($docArray);
|
|
|
|
|
+ if (!$tns) throw new Exception("targetNamespace not defined");
|
|
|
|
|
+ foreach ($docArray[1] as $attr => $val) {
|
|
|
|
|
+ if ('xmlns:' !== substr($attr, 0, 6)) continue;
|
|
|
|
|
+ if ($tns === $val) return substr($attr, 6);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new Exception("Missing targetNamespace xmlns:...");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static function findElementName($docArray, $nodeArray) {
|
|
public static function findElementName($docArray, $nodeArray) {
|
|
|
if (!empty($nodeArray[1]['name'])) return $nodeArray[1]['name'];
|
|
if (!empty($nodeArray[1]['name'])) return $nodeArray[1]['name'];
|
|
|
if (!empty($nodeArray[1]['ref'])) return $nodeArray[1]['ref'];
|
|
if (!empty($nodeArray[1]['ref'])) return $nodeArray[1]['ref'];
|
|
@@ -83,7 +107,72 @@ class XML {
|
|
|
if (!empty($nodeArray[1]['type'])) {
|
|
if (!empty($nodeArray[1]['type'])) {
|
|
|
// TODO:TYPE_RECURCE: if local ns prefix then find correct typeName?
|
|
// TODO:TYPE_RECURCE: if local ns prefix then find correct typeName?
|
|
|
// TODO:TYPE_RECURCE:the same for restrictions
|
|
// TODO:TYPE_RECURCE:the same for restrictions
|
|
|
- return $nodeArray[1]['type'];
|
|
|
|
|
|
|
+ $type = $nodeArray[1]['type'];
|
|
|
|
|
+ if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
|
|
|
|
|
+ if ('xsd:' == substr($type, 0, 4)) return $type;
|
|
|
|
|
+ list($prefix, $name) = explode(':', $type);
|
|
|
|
|
+ if ($prefix === self::findTargetNamespacePrefix($docArray)) {
|
|
|
|
|
+ $simpleTypeNode = self::findSimpleTypeNode($docArray, $name);
|
|
|
|
|
+ DBG::log($simpleTypeNode, 'array', "\$simpleTypeNode \$fieldName='{$fieldName}' type='{$type}'");
|
|
|
|
|
+ if (!empty($simpleTypeNode[1]['type'])) {
|
|
|
|
|
+ throw new Exception("TODO: findElementType node/@type => 'xsd:simpleType/@type' = '{$simpleTypeNode[1]['type']}'");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($simpleTypeNode[2][0]) && 'xsd:restriction' == $simpleTypeNode[2][0][0]) {
|
|
|
|
|
+ $restrictionNode = $simpleTypeNode[2][0];
|
|
|
|
|
+ if (empty($restrictionNode[1]['base'])) throw new Exception("Missing xsd:restriction/@base (node/@type => xsd:simpleType/[@type='{$simpleTypeNode[1]['type']}']/xsd:restriction')");
|
|
|
|
|
+ $type = $restrictionNode[1]['base'];
|
|
|
|
|
+ DBG::log($type, 'array', "findElementType \$fieldName='{$fieldName}' type='{$nodeArray[1]['type']}' => type='{$type}'");
|
|
|
|
|
+ // TODO: in findElementRestrictions or findSimpleTypeRestrictions - save current restrictions in $restrictionNode[2]
|
|
|
|
|
+ // TODO: check restrictions - if has enumeration then return 'p5:enum'
|
|
|
|
|
+ $isEnum = false;
|
|
|
|
|
+ foreach ($restrictionNode[2] as $restr) {
|
|
|
|
|
+ if ('enumeration' === self::getTagName($restr[0])) {
|
|
|
|
|
+ $isEnum = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($isEnum) return 'p5:enum';
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: recurse with limit
|
|
|
|
|
+ if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
|
|
|
|
|
+ if ('xsd:' == substr($type, 0, 4)) return $type;
|
|
|
|
|
+ list($prefix, $name) = explode(':', $type);
|
|
|
|
|
+ $simpleTypeNode = self::findSimpleTypeNode($docArray, $name);
|
|
|
|
|
+ DBG::log($simpleTypeNode, 'array', "\$simpleTypeNode \$fieldName='{$fieldName}' ... type='{$type}'");
|
|
|
|
|
+ if (!empty($simpleTypeNode[1]['type'])) {
|
|
|
|
|
+ throw new Exception("TODO: findElementType node/@type => 'xsd:simpleType/@type' = '{$simpleTypeNode[1]['type']}'");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($simpleTypeNode[2][0]) && 'xsd:restriction' == $simpleTypeNode[2][0][0]) {
|
|
|
|
|
+ $restrictionNode = $simpleTypeNode[2][0];
|
|
|
|
|
+ if (empty($restrictionNode[1]['base'])) throw new Exception("Missing xsd:restriction/@base (node/@type => xsd:simpleType/[@type='{$simpleTypeNode[1]['type']}']/xsd:restriction')");
|
|
|
|
|
+ $type = $restrictionNode[1]['base'];
|
|
|
|
|
+ DBG::log($type, 'array', "findElementType \$fieldName='{$fieldName}' ... type='{$type}'");
|
|
|
|
|
+ if ('xs:' == substr($type, 0, 3)) return "xsd:" . substr($type, 3);
|
|
|
|
|
+ if ('xsd:' == substr($type, 0, 4)) return $type;
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO: throw...
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO: throw...
|
|
|
|
|
+ // 0 => 'xsd:simpleType',
|
|
|
|
|
+ // 1 => [
|
|
|
|
|
+ // 'name' => 'PROCES_INIT_Simple',
|
|
|
|
|
+ // ],
|
|
|
|
|
+ // 2 => [
|
|
|
|
|
+ // 0 => [
|
|
|
|
|
+ // 0 => 'xsd:restriction',
|
|
|
|
|
+ // 1 => [
|
|
|
|
|
+ // 'base' => 'default_db__x3A__CRM_PROCES:TYPE_Simple',
|
|
|
|
|
+ // ],
|
|
|
|
|
+ // 2 => [
|
|
|
|
|
+ // 0 => [
|
|
|
|
|
+ // 0 => 'xsd:enumeration',
|
|
|
|
|
+ // 1 => [
|
|
|
|
|
+ // 'value' => 'PROCES_INIT',
|
|
|
|
|
+ // ],
|
|
|
|
|
+ // 2 => NULL,
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return $nodeArray[1]['type'];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!empty($nodeArray[1]['ref'])) return 'ref:' . $nodeArray[1]['ref'];
|
|
if (!empty($nodeArray[1]['ref'])) return 'ref:' . $nodeArray[1]['ref'];
|
|
|
if (empty($nodeArray[2])) throw new Exception("Missing xsd:element childrens - cannot find type");
|
|
if (empty($nodeArray[2])) throw new Exception("Missing xsd:element childrens - cannot find type");
|