diff --git a/lib/Deserializer/functions.php b/lib/Deserializer/functions.php index 62d4d0e..7a16ec9 100644 --- a/lib/Deserializer/functions.php +++ b/lib/Deserializer/functions.php @@ -215,6 +215,9 @@ function valueObject(Reader $reader, string $className, string $namespace) // Ignore property $reader->next(); } + } elseif (Reader::ELEMENT === $reader->nodeType) { + // Skipping element from different namespace + $reader->next(); } else { if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) { break; diff --git a/tests/Sabre/Xml/Deserializer/ValueObjectTest.php b/tests/Sabre/Xml/Deserializer/ValueObjectTest.php index 47d0ded..7cb5e31 100644 --- a/tests/Sabre/Xml/Deserializer/ValueObjectTest.php +++ b/tests/Sabre/Xml/Deserializer/ValueObjectTest.php @@ -81,6 +81,43 @@ public function testDeserializeValueObjectIgnoredElement() ); } + public function testDeserializeValueObjectIgnoredNamespace() + { + $input = << + + Harry + harry@example.org + Turtle + +XML; + + $reader = new Reader(); + $reader->xml($input); + $reader->elementMap = [ + '{urn:foo}foo' => function (Reader $reader) { + return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo'); + }, + ]; + + $output = $reader->parse(); + + $vo = new TestVo(); + $vo->firstName = 'Harry'; + $vo->lastName = 'Turtle'; + + $expected = [ + 'name' => '{urn:foo}foo', + 'value' => $vo, + 'attributes' => [], + ]; + + $this->assertEquals( + $expected, + $output + ); + } + public function testDeserializeValueObjectAutoArray() { $input = <<