diff --git a/src/SchemaReader.php b/src/SchemaReader.php index 8642865..abf709d 100644 --- a/src/SchemaReader.php +++ b/src/SchemaReader.php @@ -231,9 +231,13 @@ private function fillAttribute(AttributeSingle $attribute, \DOMElement $node): v if ($node->hasAttribute('nillable')) { $attribute->setNil('true' === $node->getAttribute('nillable')); } - if ($node->hasAttribute('form')) { - $attribute->setQualified('qualified' === $node->getAttribute('form')); - } + + $attribute->setQualified( + $node->hasAttribute('form') + ? 'qualified' === $node->getAttribute('form') + : $attribute->getSchema()->getAttributesQualification() + ); + if ($node->hasAttribute('use')) { $attribute->setUse($node->getAttribute('use')); } @@ -1466,9 +1470,12 @@ private function fillElement(AbstractElementSingle $element, \DOMElement $node): if ($node->hasAttribute('nillable')) { $element->setNil('true' === $node->getAttribute('nillable')); } - if ($node->hasAttribute('form')) { - $element->setQualified('qualified' === $node->getAttribute('form')); - } + + $element->setQualified( + $node->hasAttribute('form') + ? 'qualified' === $node->getAttribute('form') + : $element->getSchema()->getElementsQualification() + ); $parentNode = $node->parentNode; if ('schema' !== $parentNode->localName || self::XSD_NS !== $parentNode->namespaceURI) { diff --git a/tests/AttributesTest.php b/tests/AttributesTest.php index 90ab0f3..b303c0c 100644 --- a/tests/AttributesTest.php +++ b/tests/AttributesTest.php @@ -222,4 +222,33 @@ public function testExternalSchemaReferencingCustomAttributesInformationUnprefix $refAttr = $schema->findAttribute('customAttributesType', 'http://www.ref.com'); self::assertSame($refAttr->getSchema()->getTargetNamespace(), $customAttributes[0]->getNamespaceURI()); } + + public function testDefaultSchemaQualificationInheritance(): void + { + $schema = $this->reader->readString( + ' + + + + + + + + ' + ); + + $myType = $schema->findType('root', 'http://www.example.com'); + self::assertInstanceOf(ComplexType::class, $myType); + self::assertTrue($schema->getAttributesQualification()); + + $attribute = $myType->getAttributes()[0]; + self::assertTrue($attribute->isQualified()); + + $attribute = $myType->getAttributes()[1]; + self::assertFalse($attribute->isQualified()); + + $attribute = $myType->getAttributes()[2]; + self::assertTrue($attribute->isQualified()); + } } diff --git a/tests/ElementsTest.php b/tests/ElementsTest.php index 2c9ca08..990d207 100644 --- a/tests/ElementsTest.php +++ b/tests/ElementsTest.php @@ -163,6 +163,40 @@ public function testNotQualifiedTargetQualifiedElement(): void self::assertTrue($element->isQualified()); } + public function testDefaultSchemaQualificationInheritance(): void + { + $schema = $this->reader->readString( + ' + + + + + + + + + + ' + ); + + $myType = $schema->findType('root', 'http://www.example.com'); + self::assertInstanceOf(ComplexType::class, $myType); + self::assertTrue($schema->getElementsQualification()); + + /** + * @var $element ElementSingle + */ + $element = $myType->getElements()[0]; + self::assertTrue($element->isQualified()); + + $element = $myType->getElements()[1]; + self::assertFalse($element->isQualified()); + + $element = $myType->getElements()[2]; + self::assertTrue($element->isQualified()); + } + public function testGroupRefOccurrences(): void { $schema = $this->reader->readString(