I am currently building an XML schema, with a head, a body, and potentially errors. I am dividing those three parts into different namespaces, so I'm wondering where and when I should put the URI namespace declarations in.
For example, should it be:
<head:schema xmlns:head="http://mywebsite.com/ns/head/" xmnls:body="http://mywebsite.com/ns/body/" xmlns:error="http://mywebsite.com/ns/error/">
<head:Response>
<head:MyFunctionResponse>
<body:DataObject>
<body:Parameter>Foo</body:Parameter>
<body:Parameter>Bar</body:Parameter>
</body:DataObject>
</head:MyFunctionResponse>
</head:Response>
</head:schema>
So despite there being no "error" namespace in this particular document, it is still defined, so that when the "body" namespace is replaced by an "error" namespace, <schema>
stays the same.
Or should it be more like this?
<head:schema>
<head:Response xmlns:head="http://mywebsite.com/ns/head/">
<head:MyFunctionResponse>
<body:DataObject xmnls:body="http://mywebsite.com/ns/body/">
<body:Parameter>Foo</body:Parameter>
<body:Parameter>Bar</body:Parameter>
</body:DataObject>
</head:MyFunctionResponse>
</head:Response>
</head:schema>
OR
<head:schema>
<head:Response xmlns:head="http://mywebsite.com/ns/head/">
<head:MyFunctionResponse>
<error:ThrownException xmnls:body="http://mywebsite.com/ns/error/">
<error:Id>21</error:Id>
<error:Message>Something went wrong.</error:Message>
</error:ThrownException>
</head:MyFunctionResponse>
</head:Response>
</head:schema>
where the namespace is only declared just as it is needed.
Or is this a question of style, opinion, or preference. Like "Window seat, or aisle seat?".
If it's not style, opinion, or preference, what are the guiding ideas behind the placement of the namespaces?