diff --git a/examples/encoders/simpleType/anyType-with-xsi-info.php b/examples/encoders/simpleType/anyType-with-xsi-info.php index 2ca3522..d875f75 100644 --- a/examples/encoders/simpleType/anyType-with-xsi-info.php +++ b/examples/encoders/simpleType/anyType-with-xsi-info.php @@ -6,7 +6,6 @@ use Soap\Encoding\Encoder\SimpleType\ScalarTypeEncoder; use Soap\Encoding\Encoder\XmlEncoder; use Soap\Encoding\EncoderRegistry; -use Soap\Engine\Metadata\Model\TypeMeta; use Soap\WsdlReader\Model\Definitions\BindingUse; use VeeWee\Reflecta\Iso\Iso; @@ -41,17 +40,10 @@ public function iso(Context $context): Iso /** * This method allows to change the context on the wrapping elementEncoder. * By forcing the bindingUse to `ENCODED`, we can make sure the xsi:type attribute is added. - * We also make sure the type is not qualified so that the xsi:type prefix xmlns is imported as well. */ public function enhanceElementContext(Context $context): Context { - return $context - ->withBindingUse(BindingUse::ENCODED) - ->withType( - $context->type->withMeta( - static fn (TypeMeta $meta): TypeMeta => $meta->withIsQualified(false) - ) - ); + return $context->withBindingUse(BindingUse::ENCODED); } } ); diff --git a/src/Xml/Writer/ElementValueBuilder.php b/src/Xml/Writer/ElementValueBuilder.php index 723d6bb..669f908 100644 --- a/src/Xml/Writer/ElementValueBuilder.php +++ b/src/Xml/Writer/ElementValueBuilder.php @@ -47,10 +47,14 @@ private function buildXsiType(XMLWriter $writer): Generator return; } + $context = $this->context; + $type = $context->type; + yield from (new XsiAttributeBuilder( $this->context, - XsiTypeDetector::detectFromValue($this->context, $this->value), - includeXsiTargetNamespace: !$this->context->type->getMeta()->isQualified()->unwrapOr(false) + XsiTypeDetector::detectFromValue($context, $this->value), + includeXsiTargetNamespace: $type->getXmlTargetNamespace() !== $type->getXmlNamespace() + || !$type->getMeta()->isQualified()->unwrapOr(false) ))($writer); }