diff --git a/Generator/Parser/XsdParser.php b/Generator/Parser/XsdParser.php index f0197bd..06e571e 100644 --- a/Generator/Parser/XsdParser.php +++ b/Generator/Parser/XsdParser.php @@ -82,6 +82,14 @@ protected function addChildrenElements($parentNode, &$parentElement) $this->setComplexTypeChildrenRecursively($node, $element); $parentElement->addChild($element); + + } elseif ($this->isCustomTypeNode($node)) { + $element = new Parser\Element\ComplexTypeElement(); + $element->setName($node->getAttribute('name')); + $this->setCustomTypeChildrenRecursively($node, $element); + + $parentElement->addChild($element); + } else { $element = new Parser\Element\Element(); $element->setName($node->getAttribute('name')); @@ -155,4 +163,98 @@ protected function setComplexTypeChildrenRecursively($node, &$element) } } } + + + /** + * Checks if the node is custom Type which is user Defined. + * It is a Complex type but name given by user. + * + * If given type of the element is not ComplexType but there is root level element with that name, + * it is supposed to be custom Node.. + * + * Example of XML + * + * + + + This is an example of complex Element + + + + + + Unique id + + + + + + + + + + + Bill to address + + + + + + + + + + + Customer title + + + + + + * + * @param DomNode $node + * + * @return boolean + */ + protected function isCustomTypeNode($node) + { + $nodes = $this->start->childNodes; + + $nodeType = $node->nodeType; + $typeAttribute = $node->getAttribute('type'); + + if ($nodeType === XML_ELEMENT_NODE) { + if (!empty($typeAttribute)) { + foreach ($nodes as $node) { + //If any Node exists with the same name as Attribute Type defined for any element + if (method_exists($node, 'getAttribute')) { + if ($typeAttribute === $node->getAttribute('name')) { + return true; + } + } + } + } + } + return false; + } + + /** + * Sets Children of Custom Type Recursively + * @param DomNode $node + * @param Element $element + */ + protected function setCustomTypeChildrenRecursively($node, &$element) + { + $nodes = $this->start->childNodes; + $typeAttribute = $node->getAttribute('type'); + + foreach ($nodes as $node) { + //If any Node exists with the same name as Attribute Type defined for any element + if (method_exists($node, 'getAttribute')) { + if ($typeAttribute === $node->getAttribute('name')) { + $this->addChildrenElements($node, $element); + } + } + } + } } \ No newline at end of file