How to use XSD for non namespaced documents

26 views Asked by At

Recently I've encountered a service that returns its results in XML, in sort of following fashion

<event>
  <event-header>
    ...
  </event-header>
  <event-body>
    ...
  </event-body>
</event>

Notice that the document does not have a namespace definition. As a result, there is no "official" schema that I can use.

I have written a schema definition that I can use to generate classes that are usable in code to interact with equivalent elements in the document. From observation I can tell that the document format does not change (field order remains the same, fields are not introduced or go away). But question stands, can I still deserialize the provided document using my schema? As far as I know, schemas must define a namespace, and in theory the documents above and below

<event xmlns="http://saltyjuice.lt/dragas/event-service/1.0/event-schema.xsd">
  <event-header>
    ...
  </event-header>
  <event-body>
    ...
  </event-body>
</event>

are not equivalent.

For reference, I'm using stax and woodstox 6 as implementation.

1

There are 1 answers

1
Michael Kay On BEST ANSWER

You can have a schema for a no-namespace document, I don't know why you thought otherwise. It's not ideal, because a namespace can guide people to the right schema. But it's allowed. Anyway, even with a namespace, it's quite possible to have several schemas for the same namespace (usually, versions and variants).