The XML (simplified):
<?xml version="1.0" encoding="UTF-8"?>
<mx:XMLimport xmlns:mx="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Leverancier>nn</Leverancier>
<Bestandsversie>1.1.0.0</Bestandsversie>
</mx:XMLimport>
The XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="XMLimport">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Leverancier" type="xsd:string" minOccurs="1"/>
<xsd:element name="Bestandsversie" type="xsd:string" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If I remove the mx: prefix from the root element of the XML it validates just fine. I'm lost in name spaces and I'm searching the internet for several hours now. I can't change the XML so the XSD have to be adapted to allow the mx: prefix. The validator gives this error:
ERROR: Element '{http://www.w3.org/2001/XMLSchema}XMLimport':
No matching global declaration available for the validation root.
I assume your question is what should the XSD look like to match your XML. This is the corrected XSD:
Your XSD doesn't define a
targetNamespaceattribute. Hence, your XMLimport must show without a namespace in instance documents; this is why when you remove the namespace from your XMLimport in the XML document, it becomes valid.If you add
targetNamespace="http://www.w3.org/2001/XMLSchema"you'll now have an XSD that will validate your XML; in general, the value of the targetNamespace must match the namespace of your document element (chameleon XSDs are a special case).Another thing at play here is
elementFormDefaultwhich by default isunqualified. This setting is that which makes the inner elementsLeverancierandBestandsversiewithout a namespace.Another thing to notice is that while it is highly unusual to see user defined content targeting the
http://www.w3.org/2001/XMLSchemanamespace, there's no provision in the XSD 1.0 spec which would explicitly prohibit users to target this namespace. This is unlike the other namespace you see in your sample XML,http://www.w3.org/2001/XMLSchema-instance: it is explicitly prohibited to target this namespace in user defined XSDs.This SO post might help, too.