Java xsd validation of xml without namespace

前端 未结 1 1503
孤街浪徒
孤街浪徒 2020-12-09 12:17

I want to validate an XML file against an XSD schema. The XML files root element does not have any namespace or xsi details. It has no attributes so just <

相关标签:
1条回答
  • 2020-12-09 12:48

    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.

    0 讨论(0)
提交回复
热议问题