diff --git a/src/Schema/MetaInformation.php b/src/Schema/MetaInformation.php
index 9b3ca9b..e76e97a 100644
--- a/src/Schema/MetaInformation.php
+++ b/src/Schema/MetaInformation.php
@@ -11,16 +11,39 @@
*/
class MetaInformation
{
+ /**
+ * Links to the schema in which this information is contained.
+ * This context schema can be used to resolve e.g. a type.
+ *
+ * Example:
+ * wsdl:arrayType="int"
+ *
+ * value = "int"
+ * contextSchema = xsd : "http://www.w3.org/2001/XMLSchema"
+ * schema = wsdl : "http://schemas.xmlsoap.org/wsdl/"
+ *
+ * The type would be xsd:int
+ */
+ private Schema $contextSchema;
+
+ /**
+ * Links to the schema that holds the declaration of the meta information type.
+ * The meta information would be located inside the "schema-prefix:name" attribute.
+ */
private Schema $schema;
+
private string $name;
+
private string $value;
public function __construct(
Schema $schema,
+ Schema $contextSchema,
string $name,
string $value
) {
$this->schema = $schema;
+ $this->contextSchema = $contextSchema;
$this->name = $name;
$this->value = $value;
}
@@ -30,6 +53,11 @@ public function getSchema(): Schema
return $this->schema;
}
+ public function getContextSchema(): Schema
+ {
+ return $this->contextSchema;
+ }
+
public function getName(): string
{
return $this->name;
diff --git a/src/SchemaReader.php b/src/SchemaReader.php
index 3f33de7..52c28e8 100644
--- a/src/SchemaReader.php
+++ b/src/SchemaReader.php
@@ -252,6 +252,7 @@ private function loadMetaAttributesForElement(SchemaItem $item, \DOMElement $nod
if (null !== $attr->namespaceURI && self::XSD_NS !== $attr->namespaceURI) {
$meta[] = new MetaInformation(
$this->findSchemaForNamespace($item->getSchema(), $attr->namespaceURI),
+ $this->findSchemaForNamespace($item->getSchema(), $attr->parentNode->namespaceURI),
$attr->name,
$attr->value
);
diff --git a/tests/AttributesTest.php b/tests/AttributesTest.php
index 68b4f8d..2ee7cdc 100644
--- a/tests/AttributesTest.php
+++ b/tests/AttributesTest.php
@@ -11,6 +11,7 @@
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Group;
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType;
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
+use GoetasWebservices\XML\XSDReader\SchemaReader;
class AttributesTest extends BaseTest
{
@@ -164,18 +165,18 @@ public function testMetaInformation(): void
self::assertSame($myAttribute->getSchema(), $meta[0]->getSchema());
}
- public function testExternalSchemaReferencingMetaInformation(): void
+ public function testExternalSchemaReferencingMetaInformationPrefixed(): void
{
$dom = new \DOMDocument();
$dom->loadXML(
'
-
+
-
+
');
@@ -186,10 +187,42 @@ public function testExternalSchemaReferencingMetaInformation(): void
$meta = $myAttribute->getMeta();
self::assertCount(1, $meta);
- self::assertEquals('meta', $meta[0]->getName());
- self::assertEquals('hello', $meta[0]->getValue());
+ self::assertEquals('metaType', $meta[0]->getName());
+ self::assertEquals('xs:string', $meta[0]->getValue());
+
+ $refAttr = $schema->findAttribute('metaType', 'http://www.ref.com');
+ self::assertSame($refAttr->getSchema(), $meta[0]->getSchema());
+ self::assertSame(SchemaReader::XSD_NS, $meta[0]->getContextSchema()->getTargetNamespace());
+ }
+
+ public function testExternalSchemaReferencingMetaInformationUnprefixed(): void
+ {
+ $dom = new \DOMDocument();
+ $dom->loadXML(
+ '
+
+
+
+
+
+
+
+
+
+ ');
+ $schema = $this->reader->readNodes(iterator_to_array($dom->documentElement->childNodes), 'file.xsd');
+
+ $myAttribute = $schema->findAttribute('myAttribute', 'http://www.example.com');
+ self::assertInstanceOf(AttributeDef::class, $myAttribute);
+
+ $meta = $myAttribute->getMeta();
+
+ self::assertCount(1, $meta);
+ self::assertEquals('metaType', $meta[0]->getName());
+ self::assertEquals('string', $meta[0]->getValue());
- $refAttr = $schema->findAttribute('meta', 'http://www.ref.com');
+ $refAttr = $schema->findAttribute('metaType', 'http://www.ref.com');
self::assertSame($refAttr->getSchema(), $meta[0]->getSchema());
+ self::assertSame(SchemaReader::XSD_NS, $meta[0]->getContextSchema()->getTargetNamespace());
}
}