简体   繁体   中英

XML namespaces architecture: Common / Shared, Request / Input, Response / Output

I'm working on XML Schemas (XSD) for my application for 1) input (request) and 2) output (response) data. Input and output data structures share some Complex- and SimpleType that are used in both input and output data structures.

My approach is: I have a common.xsd that I include in both input.xsd and output.xsd . As I use include (instead of import ), all schemas share a single XML namespace , eg

http://example.org/MyApplication

common.xsd does not declare any elements, only types. The actual elements are defined in input.xsd and output.xsd .

Should I have different namespaces for all 3 schemas? Eg

  • http://example.org/MyApplication/common ,
  • http://example.org/MyApplication/request ,
  • http://example.org/MyApplication/response ?

What are the implications or pros/cons of having a) a shared namespace for all schemas and b) different namespaces for these schemas? I'm not sure what's the right approach.

My inclination would be to use a single namespace for all three. It makes it easier to re-use definitions across different parts of the application.

There are only really two good reasons for using multiple namespaces: (a) there is a very real prospect of local names clashing, and/or (b) different vocabularies are defined by different naming authorities and there's no overall point of change control.

To be honest though, this is too big a question for a simple Q&A on Stack Overflow. I once spent months consulting with a large bank that was struggling with how to design schemas and namespaces for 400 different message types that were being used for data interchange within the organisation - which of course had a lot of shared parts, often with variations for different messages - and the bottom line is that there is no easy answer. But what I learnt from the exercise is that it all depends how you want to manage change. If control is very decentralised, go for separate namespaces and schemas; if you want to maximise integration and reuse, go for a single namespace that embraces everything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM