I'm trying to validate a really simple xml using xsd, but for some reason I get this error. I'll really appreciate if someone can explain me why.
XML File
<?xml version="1.0" encoding="utf-8"?>
<MyElement>A</MyElement>
XSD File
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Test"
xmlns:tns="http://www.example.org/Test"
elementFormDefault="qualified">
<simpleType name="MyType">
<restriction base="string"></restriction>
</simpleType>
<element name="MyElement" type="tns:MyType"></element>
</schema>
I had this error for my XXX element and it was because my XSD was wrongly formatted according to javax.xml.bind v2.2.11 . I think it's using an older XSD format but I didn't bother to confirm.
My initial wrong XSD was alike the following:
The good XSD format for my migration to succeed was the following:
And so on for every similar XSD nodes.
Your schema is for its target namespace
http://www.example.org/Test
so it defines an element with nameMyElement
in that target namespacehttp://www.example.org/Test
. Your instance document however has an element with nameMyElement
in no namespace. That is why the validating parser tells you it can't find a declaration for that element, you haven't provided a schema for elements in no namespace.You either need to change the schema to not use a target namespace at all or you need to change the instance to use e.g.
<MyElement xmlns="http://www.example.org/Test">A</MyElement>
.