[xsd-users] Namespace mapping problem

Boris Kolpackov boris at codesynthesis.com
Tue Jan 20 10:43:31 EST 2015


Hi Joseph,

Gagnon, Joseph - 0558 - MITLL <Joseph.Gagnon at ll.mit.edu> writes:

> I get the following from XSD:
> 
> PS C:\Users\jo24447> C:\Users\jo24447\Downloads\xsd-4.0.0-i686-windows\bin\xsd 
> cxx-tree C:\Users\jo24447\ServiceContract_Message.xsd
> C:\Users\jo24447\ServiceContract_Message.xsd:2:166: error: unable to map XML 
> Schema namespace 'http://www.somesite.org/' to C++ namespace
> C:\Users\jo24447\ServiceContract_Message.xsd:2:166: info: use 
> the --namespace-map or --namespace-regex option to provide custom mapping
> 
> If I change the target to something I know is a valid existing URL (e.g. 
> http://www.google.com) the error above no longer occurs (although I do get 
> other errors that appear to be related).

The targetNamespace attribute can contain anything. It doesn't have to
be a URL. Quite a few schemas use the foo:bar:baz format. XSD tries to
automatically map some commonly-used formats (e.g., URL with some path
after the host name, etc) to C++ namespaces but it cannot always do
this. When it can't it issues the above error. But, and that's what
baffles me about your situation, it is extremely easy to resolve
with the --namespace-map option, as helpfully suggested by the error
message. Simply adding:

--namespace-map http://www.somesite.org/=SomeCxxNamespace

to the command line should solve this problem. If that doesn't work
for you for some reason, please send detailed description of how
exactly it doesn't work (e.g., error messages, generated code looks
wrong, etc).


> I was expecting different types to be  broken out into separate files

You can get this behavior with the --file-per-type option though unless
you really have to use this mode, it is not recommended. See this post
for details:

http://www.codesynthesis.com/~boris/blog/2008/02/13/codesynthesis-xsd-3-1-0-released/

Boris



More information about the xsd-users mailing list