Java xsd validation of xml without namespace Java xsd validation of xml without namespace xml xml

Java xsd validation of xml without namespace


You have two separate concerns you need to take care of:

  1. Declaring the namespace that your document uses.
  2. 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.