Java xsd validation of xml without namespace
You have two separate concerns you need to take care of:
- Declaring the namespace that your document uses.
- Putting an
xsi:schemaLocation
attribute in the file to give a hint (!) where the schema is.
You can safely skip the second part, as the location is really only a hint. You cannot skip the first part. The namespace declared in the XML file is matched against the schema. Important, this:
<xml> ... </xml>
Is not the same as this:
<xml xmlns="urn:foo"> ... </xml>
So you need to declare your namespace in the XML document, otherwise it will not correspond to your schema and you will get this error.